From d18314357fb142d98cfc4693d41fb60cae34e0b6 Mon Sep 17 00:00:00 2001 From: tophf Date: Sun, 2 Aug 2020 07:00:44 +0300 Subject: [PATCH] use onBoundsChanged to remember editor size/position (#1007) --- 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();