use onBoundsChanged to remember editor size/position (#1007)

This commit is contained in:
tophf 2020-08-02 07:00:44 +03:00 committed by GitHub
parent f8402a2211
commit d18314357f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();