From 96725719130426e6b2bc4bc9bca4a6bc3b3d9706 Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Wed, 2 Oct 2024 03:10:22 -0400 Subject: [PATCH] autocomplete-textarea: Reposition popup on resize (#4718) --- .../zotero/elements/autocompleteTextArea.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/chrome/content/zotero/elements/autocompleteTextArea.js b/chrome/content/zotero/elements/autocompleteTextArea.js index 31eb0032cf..5565e21e54 100644 --- a/chrome/content/zotero/elements/autocompleteTextArea.js +++ b/chrome/content/zotero/elements/autocompleteTextArea.js @@ -23,6 +23,10 @@ this.popupSelectedIndex = -1; + this._lastMoveHeight = null; + + this._resizeObserver = new ResizeObserver(() => this.movePopup()); + XPCOMUtils.defineLazyPreferenceGetter( this, "disablePopupAutohide", @@ -117,6 +121,12 @@ ); this.valueIsTyped = false; + + this._resizeObserver.observe(this); + } + + disconnectedCallback() { + this._resizeObserver.unobserve(this); } get popup() { @@ -426,6 +436,22 @@ return; } this.popup.closePopup(); + this._lastMoveHeight = null; + } + + movePopup() { + let height = this.getBoundingClientRect().height; + if (this.popupOpen && height !== this._lastMoveHeight) { + // https://searchfox.org/mozilla-central/rev/1b90936792b2c71ef931cb1b8d6baff9d825592e/toolkit/content/widgets/autocomplete-popup.js#282 + this.popup.moveToAnchor( + this.popup.anchorNode, + "after_start", + 0, + 0, + false + ); + this._lastMoveHeight = height; + } } showHistoryPopup() {