This commit is contained in:
Simon Cambier
2024-03-30 18:24:53 +01:00
4 changed files with 30 additions and 4 deletions

View File

@@ -47,6 +47,7 @@
let openInCurrentPaneKey: string let openInCurrentPaneKey: string
let createInNewPaneKey: string let createInNewPaneKey: string
let createInCurrentPaneKey: string let createInCurrentPaneKey: string
let openInNewLeafKey: string = getCtrlKeyLabel() + ' alt ↵'
$: selectedNote = resultNotes[selectedIndex] $: selectedNote = resultNotes[selectedIndex]
$: searchQuery = searchQuery ?? previousQuery $: searchQuery = searchQuery ?? previousQuery
@@ -101,6 +102,7 @@
eventBus.on('vault', Action.ArrowDown, () => moveIndex(1)) eventBus.on('vault', Action.ArrowDown, () => moveIndex(1))
eventBus.on('vault', Action.PrevSearchHistory, prevSearchHistory) eventBus.on('vault', Action.PrevSearchHistory, prevSearchHistory)
eventBus.on('vault', Action.NextSearchHistory, nextSearchHistory) eventBus.on('vault', Action.NextSearchHistory, nextSearchHistory)
eventBus.on('vault', Action.OpenInNewLeaf, openNoteInNewLeaf)
await NotesIndex.refreshIndex() await NotesIndex.refreshIndex()
await updateResultsDebounced() await updateResultsDebounced()
}) })
@@ -178,16 +180,26 @@
modal.close() modal.close()
} }
function openNoteInNewLeaf(): void {
if (!selectedNote) return
openSearchResult(selectedNote, true, true)
modal.close()
}
function saveCurrentQuery() { function saveCurrentQuery() {
if (searchQuery) { if (searchQuery) {
cacheManager.addToSearchHistory(searchQuery) cacheManager.addToSearchHistory(searchQuery)
} }
} }
function openSearchResult(note: ResultNote, newPane = false) { function openSearchResult(
note: ResultNote,
newPane = false,
newLeaf = false
) {
saveCurrentQuery() saveCurrentQuery()
const offset = note.matches?.[0]?.offset ?? 0 const offset = note.matches?.[0]?.offset ?? 0
openNote(note, offset, newPane) openNote(note, offset, newPane, newLeaf)
} }
async function onClickCreateNote(_e: MouseEvent) { async function onClickCreateNote(_e: MouseEvent) {
@@ -354,6 +366,11 @@
<span>to open in a new pane</span> <span>to open in a new pane</span>
</div> </div>
<div class="prompt-instruction">
<span class="prompt-instruction-command">{openInNewLeafKey}</span>
<span>to open in a new split</span>
</div>
<div class="prompt-instruction"> <div class="prompt-instruction">
<span class="prompt-instruction-command">alt o</span> <span class="prompt-instruction-command">alt o</span>
<span>to open in the background</span> <span>to open in the background</span>

View File

@@ -68,6 +68,7 @@ abstract class OmnisearchModal extends Modal {
let openInNewPaneKey: Modifier[] let openInNewPaneKey: Modifier[]
let createInCurrentPaneKey: Modifier[] let createInCurrentPaneKey: Modifier[]
let createInNewPaneKey: Modifier[] let createInNewPaneKey: Modifier[]
let openInNewLeafKey: Modifier[] = ['Mod', 'Alt']
if (settings.openInNewPane) { if (settings.openInNewPane) {
openInCurrentPaneKey = ['Mod'] openInCurrentPaneKey = ['Mod']
openInNewPaneKey = [] openInNewPaneKey = []
@@ -86,6 +87,12 @@ abstract class OmnisearchModal extends Modal {
eventBus.emit(Action.OpenInNewPane) eventBus.emit(Action.OpenInNewPane)
}) })
// Open in a new leaf
this.scope.register(openInNewLeafKey, 'Enter', e => {
e.preventDefault()
eventBus.emit(Action.OpenInNewLeaf)
})
// Insert link // Insert link
this.scope.register(['Alt'], 'Enter', e => { this.scope.register(['Alt'], 'Enter', e => {
e.preventDefault() e.preventDefault()

View File

@@ -43,6 +43,7 @@ export const enum Action {
ArrowDown = 'arrow-down', ArrowDown = 'arrow-down',
PrevSearchHistory = 'prev-search-history', PrevSearchHistory = 'prev-search-history',
NextSearchHistory = 'next-search-history', NextSearchHistory = 'next-search-history',
OpenInNewLeaf = 'open-in-new-leaf',
} }
export type DocumentRef = { path: string; mtime: number } export type DocumentRef = { path: string; mtime: number }

View File

@@ -5,7 +5,8 @@ import { stringsToRegex } from './text-processing'
export async function openNote( export async function openNote(
item: ResultNote, item: ResultNote,
offset = 0, offset = 0,
newPane = false newPane = false,
newLeaf = false
): Promise<void> { ): Promise<void> {
// Check if the note is already open, // Check if the note is already open,
// to avoid opening it twice if the first one is pinned // to avoid opening it twice if the first one is pinned
@@ -25,7 +26,7 @@ export async function openNote(
if (!alreadyOpenAndPinned) { if (!alreadyOpenAndPinned) {
// Open the note normally // Open the note normally
await app.workspace.openLinkText(item.path, '', newPane) await app.workspace.openLinkText(item.path, '', newLeaf ? 'split' : newPane)
} }
const view = app.workspace.getActiveViewOfType(MarkdownView) const view = app.workspace.getActiveViewOfType(MarkdownView)