From f8c3a3a31e6ddb2aaadb6a4c8fe8b1c0d086be51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Thu, 21 Sep 2023 10:26:02 +0300 Subject: [PATCH] Fix citation dialog being moved to the wrong location sometimes --- .../zotero/integration/addCitationDialog.js | 16 ++++++++++------ chrome/content/zotero/integration/quickFormat.js | 13 ++++++++----- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/chrome/content/zotero/integration/addCitationDialog.js b/chrome/content/zotero/integration/addCitationDialog.js index e3ba76b693..9c9f45b16e 100644 --- a/chrome/content/zotero/integration/addCitationDialog.js +++ b/chrome/content/zotero/integration/addCitationDialog.js @@ -73,15 +73,19 @@ var Zotero_Citation_Dialog = new function () { */ this.load = Zotero.Promise.coroutine(function* () { // make sure we are visible - window.setTimeout(function() { - var screenX = window.screenX; - var screenY = window.screenY; - var xRange = [window.screen.availLeft, window.screen.width-window.outerWidth]; - var yRange = [window.screen.availTop, window.screen.height-window.outerHeight]; + window.setTimeout(async function () { + let screenX = window.screenX, screenY = window.screenY, i = 5; + while (!screenX && i--) { + await new Promise(resolve => window.requestAnimationFrame(resolve)); + screenX = window.screenX; + screenY = window.screenY; + } + var xRange = [window.screen.availLeft, window.screen.left + window.screen.width - window.outerWidth]; + var yRange = [window.screen.availTop, window.screen.top + window.screen.height - window.outerHeight]; if(screenX < xRange[0] || screenX > xRange[1] || screenY < yRange[0] || screenY > yRange[1]) { var targetX = Math.max(Math.min(screenX, xRange[1]), xRange[0]); var targetY = Math.max(Math.min(screenY, yRange[1]), yRange[0]); - Zotero.debug("Moving window to "+targetX+", "+targetY); + Zotero.debug(`Moving window to ${targetX}, ${targetY}`); window.moveTo(targetX, targetY); } }, 0); diff --git a/chrome/content/zotero/integration/quickFormat.js b/chrome/content/zotero/integration/quickFormat.js index 5d8663d06d..634d963fce 100644 --- a/chrome/content/zotero/integration/quickFormat.js +++ b/chrome/content/zotero/integration/quickFormat.js @@ -157,12 +157,15 @@ var Zotero_QuickFormat = new function () { if (event.target !== document) return; // make sure we are visible let resizePromise = (async function () { - await Zotero.Promise.delay(); + let screenX = window.screenX, screenY = window.screenY, i = 5; + while (!screenX && i--) { + await new Promise(resolve => window.requestAnimationFrame(resolve)); + screenX = window.screenX; + screenY = window.screenY; + } window.resizeTo(window.outerWidth, qfb.clientHeight); - var screenX = window.screenX; - var screenY = window.screenY; - var xRange = [window.screen.availLeft, window.screen.width - window.outerWidth]; - var yRange = [window.screen.availTop, window.screen.height - window.outerHeight]; + var xRange = [window.screen.availLeft, window.screen.left + window.screen.width - window.outerWidth]; + var yRange = [window.screen.availTop, window.screen.top + window.screen.height - window.outerHeight]; if (screenX < xRange[0] || screenX > xRange[1] || screenY < yRange[0] || screenY > yRange[1]) { var targetX = Math.max(Math.min(screenX, xRange[1]), xRange[0]); var targetY = Math.max(Math.min(screenY, yRange[1]), yRange[0]);