From 9c597fec0d1871105147ae46b9b3b2bf639127e0 Mon Sep 17 00:00:00 2001 From: tophf Date: Fri, 31 Jul 2020 12:21:33 +0300 Subject: [PATCH] use onBoundsChanged to remember editor size/position --- edit/edit.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/edit/edit.js b/edit/edit.js index b7cf2846..4c5d098d 100644 --- a/edit/edit.js +++ b/edit/edit.js @@ -172,8 +172,19 @@ preinit(); $('#name').title = usercss ? t('usercssReplaceTemplateName') : ''; $('#preview-label').classList.toggle('hidden', !style.id); initBeautifyButton($('#beautify'), () => editor.getEditors()); + const {onBoundsChanged} = chrome.windows || {}; + if (onBoundsChanged) { + // * movement is reported even if the window wasn't resized + // * fired just once when done so debounce is not needed + onBoundsChanged.addListener(wnd => { + // getting the current window id as it may change if the user attached/detached the tab + chrome.windows.getCurrent(ownWnd => { + if (wnd.id === ownWnd.id) rememberWindowSize(); + }); + }); + } window.addEventListener('resize', () => { - debounce(rememberWindowSize, 100); + if (!onBoundsChanged) debounce(rememberWindowSize, 100); detectLayout(); }); detectLayout();