From f9e25675f0cc4060dc59e2471d08f1fa45cd1099 Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Thu, 28 Mar 2024 13:13:10 -0400 Subject: [PATCH] editable-text: Prevent dropping text into read-only field --- chrome/content/zotero/elements/editableText.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/chrome/content/zotero/elements/editableText.js b/chrome/content/zotero/elements/editableText.js index 9abc466edb..efd3af9448 100644 --- a/chrome/content/zotero/elements/editableText.js +++ b/chrome/content/zotero/elements/editableText.js @@ -260,24 +260,25 @@ input.addEventListener('dragover', (event) => { // If the input is not focused, override the default drop behavior if ((document.activeElement !== this._input || Services.focus.activeWindow !== window) + && !this.readOnly && event.dataTransfer.getData('text/plain')) { event.preventDefault(); event.dataTransfer.dropEffect = 'copy'; } }); input.addEventListener('drop', (event) => { - let text = event.dataTransfer.getData('text/plain'); // If the input is not focused, replace its entire value with the dropped text // Otherwise, the normal drop effect takes place and the text is inserted at the cursor if ((document.activeElement !== this._input || Services.focus.activeWindow !== window) - && text) { + && !this.readOnly + && event.dataTransfer.getData('text/plain')) { event.preventDefault(); document.activeElement?.blur(); // Wait a tick to work around an apparent Firefox bug where the cursor stays inside the old // input even though the new input becomes visually focused setTimeout(() => { this.focus(); - this._input.value = text; + this._input.value = event.dataTransfer.getData('text/plain'); handleInput(); }); }