#206 - Added ctrl+enter shortcut for InFile results

This commit is contained in:
Simon Cambier
2023-03-09 21:29:09 +01:00
parent c4cf6a70bf
commit e611202da2
2 changed files with 14 additions and 10 deletions

View File

@@ -6,7 +6,7 @@
type ResultNote, type ResultNote,
type SearchMatch, type SearchMatch,
} from 'src/globals' } from 'src/globals'
import { loopIndex } from 'src/tools/utils' import { getCtrlKeyLabel, loopIndex } from 'src/tools/utils'
import { onDestroy, onMount, tick } from 'svelte' import { onDestroy, onMount, tick } from 'svelte'
import { MarkdownView } from 'obsidian' import { MarkdownView } from 'obsidian'
import ModalContainer from './ModalContainer.svelte' import ModalContainer from './ModalContainer.svelte'
@@ -36,6 +36,7 @@
eventBus.enable('infile') eventBus.enable('infile')
eventBus.on('infile', 'enter', openSelection) eventBus.on('infile', 'enter', openSelection)
eventBus.on('infile', 'open-in-new-pane', openSelectionInNewTab)
eventBus.on('infile', 'arrow-up', () => moveIndex(-1)) eventBus.on('infile', 'arrow-up', () => moveIndex(-1))
eventBus.on('infile', 'arrow-down', () => moveIndex(1)) eventBus.on('infile', 'arrow-down', () => moveIndex(1))
eventBus.on('infile', 'tab', switchToVaultModal) eventBus.on('infile', 'tab', switchToVaultModal)
@@ -108,15 +109,17 @@
elem?.scrollIntoView({ behavior: 'auto', block: 'nearest' }) elem?.scrollIntoView({ behavior: 'auto', block: 'nearest' })
} }
async function openSelection( async function openSelectionInNewTab(): Promise<void> {
evt?: MouseEvent | KeyboardEvent return openSelection(true)
): Promise<void> { }
async function openSelection(newTab = false): Promise<void> {
if (note) { if (note) {
modal.close() modal.close()
if (parent) parent.close() if (parent) parent.close()
// Open (or switch focus to) the note // Open (or switch focus to) the note
await openNote(note, evt?.ctrlKey) await openNote(note, newTab)
// Move cursor to the match // Move cursor to the match
const view = app.workspace.getActiveViewOfType(MarkdownView) const view = app.workspace.getActiveViewOfType(MarkdownView)
@@ -157,7 +160,7 @@
index="{i}" index="{i}"
selected="{i === selectedIndex}" selected="{i === selectedIndex}"
on:mousemove="{_e => (selectedIndex = i)}" on:mousemove="{_e => (selectedIndex = i)}"
on:click="{openSelection}" /> on:click="{(evt) => openSelection(evt.ctrlKey)}" />
{/each} {/each}
{:else} {:else}
<div style="text-align: center;"> <div style="text-align: center;">
@@ -185,4 +188,9 @@
<span>to close</span> <span>to close</span>
{/if} {/if}
</div> </div>
<div class="prompt-instruction">
<span class="prompt-instruction-command">{getCtrlKeyLabel()}</span>
<span>to open in a new pane</span>
</div>
</div> </div>

View File

@@ -319,8 +319,6 @@
<span>to switch to In-File Search</span> <span>to switch to In-File Search</span>
</div> </div>
<br />
<div class="prompt-instruction"> <div class="prompt-instruction">
<span class="prompt-instruction-command">{getCtrlKeyLabel()}</span> <span class="prompt-instruction-command">{getCtrlKeyLabel()}</span>
<span>to open in a new pane</span> <span>to open in a new pane</span>
@@ -334,8 +332,6 @@
<span>to create in a new pane</span> <span>to create in a new pane</span>
</div> </div>
<br />
<div class="prompt-instruction"> <div class="prompt-instruction">
<span class="prompt-instruction-command">alt ↵</span> <span class="prompt-instruction-command">alt ↵</span>
<span>to insert a link</span> <span>to insert a link</span>