From 2e135d035fd5747466a38dc4ae93d26a06b1485b Mon Sep 17 00:00:00 2001 From: abaevbog Date: Tue, 29 Jul 2025 00:05:45 -0500 Subject: [PATCH] Fx140: do not use bluebird methods in citation dialog (#5416) Instead, decide if the search should be skipped after the delay based on the timestamps. Fixes: #5414 --- .../zotero/integration/citationDialog.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/chrome/content/zotero/integration/citationDialog.js b/chrome/content/zotero/integration/citationDialog.js index a92e695527..7f6c09d9bd 100644 --- a/chrome/content/zotero/integration/citationDialog.js +++ b/chrome/content/zotero/integration/citationDialog.js @@ -197,7 +197,7 @@ function _id(id) { class Layout { constructor(type) { this.type = type; - this._searchDebouncePromise = null; + this._lastSearchTime = null; } // Re-render the items based on search results @@ -319,15 +319,17 @@ class Layout { await this.refreshItemsList({ skipWindowResize: true }); // debounce to not rerun sql search until typing is probably done - if (this._searchDebouncePromise && this._searchDebouncePromise.isPending()) { - this._searchDebouncePromise.cancel(); - } if (!skipDebounce) { - this._searchDebouncePromise = Zotero.Promise.delay(SEARCH_TIMEOUT); - await this._searchDebouncePromise; + // record when the search started + let searchStartTime = Date.now(); + this._lastSearchTime = searchStartTime; + + // wait a moment + await Zotero.Promise.delay(SEARCH_TIMEOUT); + + // stop if another search started during the delay + if (this._lastSearchTime !== searchStartTime) return; } - this._searchDebouncePromise = null; - // in list mode, search for matches across libraries // in library mode, set filter on itemTree if (this.type == "list") {