From c10dabcbba5e155998e071a1690200064156f1cd Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Mon, 29 Jan 2024 15:43:36 -0500 Subject: [PATCH] Ignore editable-text blurs caused by window becoming inactive Fixes #3588 --- chrome/content/zotero/elements/editableText.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/chrome/content/zotero/elements/editableText.js b/chrome/content/zotero/elements/editableText.js index 35f398c60a..e7c38d42c3 100644 --- a/chrome/content/zotero/elements/editableText.js +++ b/chrome/content/zotero/elements/editableText.js @@ -31,6 +31,8 @@ _textDirection = null; + _ignoredWindowInactiveBlur = false; + static observedAttributes = [ 'multiline', 'readonly', @@ -186,6 +188,13 @@ input.addEventListener('input', handleInput); input.addEventListener('change', handleChange); input.addEventListener('focus', () => { + // If the last blur was ignored because it was caused by the window becoming inactive, + // ignore this focus event as well, so we don't reset initialValue + if (this._ignoredWindowInactiveBlur) { + this._ignoredWindowInactiveBlur = false; + return; + } + this.dispatchEvent(new CustomEvent('focus')); this.classList.add("focused"); // Select all text if focused via keyboard @@ -195,6 +204,13 @@ this._input.dataset.initialValue = this._input.value; }); input.addEventListener('blur', () => { + // Ignore this blur if it was caused by the window becoming inactive (see above) + if (Services.focus.activeWindow !== window) { + this._ignoredWindowInactiveBlur = true; + return; + } + this._ignoredWindowInactiveBlur = false; + this.dispatchEvent(new CustomEvent('blur')); this.classList.remove("focused"); this._input.scrollLeft = 0;