Use Ctrl + Shift + Click on the launcher pane to open and activate in a new tab.

This commit is contained in:
SiriusXT 2025-05-04 17:18:02 +08:00
parent d3a6079d9b
commit 9765f2f6d7
3 changed files with 18 additions and 3 deletions

View File

@ -277,10 +277,18 @@ export default class TabManager extends Component {
return noteContext; 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); const noteContext = await this.openEmptyTab(null, hoistedNoteId || this.getActiveContext()?.hoistedNoteId);
await noteContext.setNote(targetNoteId); 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) { async openInSameTab(targetNoteId: string, hoistedNoteId: string | null = null) {

View File

@ -53,11 +53,12 @@ export default class NoteLauncher extends AbstractLauncher {
await appContext.tabManager.openInSameTab(targetNoteId, hoistedNoteId); await appContext.tabManager.openInSameTab(targetNoteId, hoistedNoteId);
} else { } else {
const ctrlKey = utils.isCtrlKey(evt); const ctrlKey = utils.isCtrlKey(evt);
const activate = evt.shiftKey ? true : false;
if ((evt.which === 1 && ctrlKey) || evt.which === 2) { if ((evt.which === 1 && ctrlKey) || evt.which === 2) {
// TODO: Fix once tabManager is ported. // TODO: Fix once tabManager is ported.
//@ts-ignore //@ts-ignore
await appContext.tabManager.openInNewTab(targetNoteId, hoistedNoteId); await appContext.tabManager.openInNewTab(targetNoteId, hoistedNoteId, activate);
} else { } else {
// TODO: Fix once tabManager is ported. // TODO: Fix once tabManager is ported.
//@ts-ignore //@ts-ignore

View File

@ -28,15 +28,21 @@ export default class OpenNoteButtonWidget extends OnClickButtonWidget {
if (evt.which === 3) { if (evt.which === 3) {
return; return;
} }
const hoistedNoteId = this.getHoistedNoteId();
const ctrlKey = utils.isCtrlKey(evt); const ctrlKey = utils.isCtrlKey(evt);
if ((evt.which === 1 && ctrlKey) || evt.which === 2) { 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 { } else {
await appContext.tabManager.openInSameTab(this.noteToOpen.noteId); await appContext.tabManager.openInSameTab(this.noteToOpen.noteId);
} }
} }
getHoistedNoteId() {
return this.noteToOpen.getRelationValue("hoistedNote") || appContext.tabManager.getActiveContext()?.hoistedNoteId;
}
initialRenderCompleteEvent() { initialRenderCompleteEvent() {
// we trigger refresh above // we trigger refresh above
} }