From 47e6a0f7abaae0ad90c9f39c385fe24efd7071bf Mon Sep 17 00:00:00 2001 From: windingwind <33902321+windingwind@users.noreply.github.com> Date: Sat, 3 Jan 2026 11:37:27 +0800 Subject: [PATCH] Fix open Note in New Window doesn't focus existing window fix: #5687 --- chrome/content/zotero/xpcom/data/notes.js | 8 +++++++- chrome/content/zotero/xpcom/editorInstance.js | 16 ++++++++++++++++ chrome/content/zotero/zoteroPane.js | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/notes.js b/chrome/content/zotero/xpcom/data/notes.js index 4b6c781b58..9a44ed2a4e 100644 --- a/chrome/content/zotero/xpcom/data/notes.js +++ b/chrome/content/zotero/xpcom/data/notes.js @@ -73,12 +73,18 @@ Zotero.Notes = new function () { if (noteEditor.viewMode === 'tab') { win.Zotero_Tabs.select(noteEditor.tabID, true); } + else { + noteEditor.focus(); + } if (location) { + // TODO: implement this noteEditor.navigate(location); } + return noteEditor; } - else if (openInWindow) { + + if (openInWindow) { let name = null; if (itemID) { diff --git a/chrome/content/zotero/xpcom/editorInstance.js b/chrome/content/zotero/xpcom/editorInstance.js index 7b15fb4f0f..b1a8140bb7 100644 --- a/chrome/content/zotero/xpcom/editorInstance.js +++ b/chrome/content/zotero/xpcom/editorInstance.js @@ -49,6 +49,18 @@ class EditorInstance { this.instanceID = Zotero.Utilities.randomString(); } + get itemID() { + return this._item.id; + } + + get viewMode() { + return this._viewMode; + } + + set viewMode(mode) { + this._viewMode = mode; + } + async init(options) { Zotero.Notes.registerEditorInstance(this); this.onNavigate = options.onNavigate; @@ -250,6 +262,7 @@ class EditorInstance { } focus() { + this._iframeWindow.focus(); this._postMessage({ action: 'focus' }); } @@ -322,6 +335,9 @@ class EditorInstance { preserveSelection }); } + + // TODO: implement navigating to note editor location + navigate(_location) {} _postMessage(message) { this._iframeWindow.postMessage({ instanceID: this.instanceID, message }, '*'); diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index 0a59c7b583..adeae44cc1 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -4655,7 +4655,7 @@ var ZoteroPane = new function () { openInWindow = Zotero.Prefs.get('openNoteInNewWindow'); } - return Zotero.Notes.open(itemID, {}, { + return Zotero.Notes.open(itemID, undefined, { openInWindow, }); };