From 9765f2f6d7ebb7a31287d2de992489b9696c320d Mon Sep 17 00:00:00 2001 From: SiriusXT <1160925501@qq.com> Date: Sun, 4 May 2025 17:18:02 +0800 Subject: [PATCH] Use Ctrl + Shift + Click on the launcher pane to open and activate in a new tab. --- apps/client/src/components/tab_manager.ts | 10 +++++++++- .../src/widgets/buttons/launcher/note_launcher.ts | 3 ++- .../src/widgets/buttons/open_note_button_widget.ts | 8 +++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/apps/client/src/components/tab_manager.ts b/apps/client/src/components/tab_manager.ts index 937bd8982..cf2876a5a 100644 --- a/apps/client/src/components/tab_manager.ts +++ b/apps/client/src/components/tab_manager.ts @@ -277,10 +277,18 @@ export default class TabManager extends Component { return noteContext; } - async openInNewTab(targetNoteId: string, hoistedNoteId: string | null = null) { + async openInNewTab(targetNoteId: string, hoistedNoteId: string | null = null, activate: boolean = false) { const noteContext = await this.openEmptyTab(null, hoistedNoteId || this.getActiveContext()?.hoistedNoteId); await noteContext.setNote(targetNoteId); + + if (activate && noteContext.notePath) { + this.activateNoteContext(noteContext.ntxId, false); + await this.triggerEvent("noteSwitchedAndActivated", { + noteContext, + notePath: noteContext.notePath + }); + } } async openInSameTab(targetNoteId: string, hoistedNoteId: string | null = null) { diff --git a/apps/client/src/widgets/buttons/launcher/note_launcher.ts b/apps/client/src/widgets/buttons/launcher/note_launcher.ts index 7622df401..00ba956a1 100644 --- a/apps/client/src/widgets/buttons/launcher/note_launcher.ts +++ b/apps/client/src/widgets/buttons/launcher/note_launcher.ts @@ -53,11 +53,12 @@ export default class NoteLauncher extends AbstractLauncher { await appContext.tabManager.openInSameTab(targetNoteId, hoistedNoteId); } else { const ctrlKey = utils.isCtrlKey(evt); + const activate = evt.shiftKey ? true : false; if ((evt.which === 1 && ctrlKey) || evt.which === 2) { // TODO: Fix once tabManager is ported. //@ts-ignore - await appContext.tabManager.openInNewTab(targetNoteId, hoistedNoteId); + await appContext.tabManager.openInNewTab(targetNoteId, hoistedNoteId, activate); } else { // TODO: Fix once tabManager is ported. //@ts-ignore diff --git a/apps/client/src/widgets/buttons/open_note_button_widget.ts b/apps/client/src/widgets/buttons/open_note_button_widget.ts index 950ded0a6..c0a4c6334 100644 --- a/apps/client/src/widgets/buttons/open_note_button_widget.ts +++ b/apps/client/src/widgets/buttons/open_note_button_widget.ts @@ -28,15 +28,21 @@ export default class OpenNoteButtonWidget extends OnClickButtonWidget { if (evt.which === 3) { return; } + const hoistedNoteId = this.getHoistedNoteId(); const ctrlKey = utils.isCtrlKey(evt); if ((evt.which === 1 && ctrlKey) || evt.which === 2) { - await appContext.tabManager.openInNewTab(this.noteToOpen.noteId); + const activate = evt.shiftKey ? true : false; + await appContext.tabManager.openInNewTab(this.noteToOpen.noteId, hoistedNoteId, activate); } else { await appContext.tabManager.openInSameTab(this.noteToOpen.noteId); } } + getHoistedNoteId() { + return this.noteToOpen.getRelationValue("hoistedNote") || appContext.tabManager.getActiveContext()?.hoistedNoteId; + } + initialRenderCompleteEvent() { // we trigger refresh above }