From f86736e140892b6f124cd37907ce73aabdf3c16a Mon Sep 17 00:00:00 2001 From: Price Baldwin <68521371+pricebaldwin@users.noreply.github.com> Date: Fri, 29 Mar 2024 16:44:18 -0400 Subject: [PATCH] Add shortcut to open note in a new split pane (PR #202) (#358) This adds the shortcut `cmd/ctrl + alt + enter` to the search modal to open a found file in a new leaf. I used the term "split" in user-facing text, because I think that's the more common Some things to note: - This function ignores the existing "open in new pane by default" setting. - It also does not check to see if the file is already open. It will continue opening the value in a new split as often as the user wants. --- src/components/ModalVault.svelte | 21 +++++++++++++++++++-- src/components/modals.ts | 7 +++++++ src/globals.ts | 1 + src/tools/notes.ts | 5 +++-- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/components/ModalVault.svelte b/src/components/ModalVault.svelte index a386a95..e31e14b 100644 --- a/src/components/ModalVault.svelte +++ b/src/components/ModalVault.svelte @@ -47,6 +47,7 @@ let openInCurrentPaneKey: string let createInNewPaneKey: string let createInCurrentPaneKey: string + let openInNewLeafKey: string = getCtrlKeyLabel() + ' alt ↵' $: selectedNote = resultNotes[selectedIndex] $: searchQuery = searchQuery ?? previousQuery @@ -101,6 +102,7 @@ eventBus.on('vault', Action.ArrowDown, () => moveIndex(1)) eventBus.on('vault', Action.PrevSearchHistory, prevSearchHistory) eventBus.on('vault', Action.NextSearchHistory, nextSearchHistory) + eventBus.on('vault', Action.OpenInNewLeaf, openNoteInNewLeaf) await NotesIndex.refreshIndex() await updateResultsDebounced() }) @@ -178,16 +180,26 @@ modal.close() } + function openNoteInNewLeaf(): void { + if (!selectedNote) return + openSearchResult(selectedNote, true, true) + modal.close() + } + function saveCurrentQuery() { if (searchQuery) { cacheManager.addToSearchHistory(searchQuery) } } - function openSearchResult(note: ResultNote, newPane = false) { + function openSearchResult( + note: ResultNote, + newPane = false, + newLeaf = false + ) { saveCurrentQuery() const offset = note.matches?.[0]?.offset ?? 0 - openNote(note, offset, newPane) + openNote(note, offset, newPane, newLeaf) } async function onClickCreateNote(_e: MouseEvent) { @@ -354,6 +366,11 @@ to open in a new pane +