Restored shift/ctrl+enter and input value selection
This commit is contained in:
@@ -9,6 +9,7 @@ const dispatch = createEventDispatcher()
|
|||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
await tick()
|
await tick()
|
||||||
input.focus()
|
input.focus()
|
||||||
|
input.select()
|
||||||
})
|
})
|
||||||
|
|
||||||
selectedNote.subscribe((note) => {
|
selectedNote.subscribe((note) => {
|
||||||
@@ -33,7 +34,16 @@ function moveNoteSelection(ev: KeyboardEvent): void {
|
|||||||
break
|
break
|
||||||
|
|
||||||
case "Enter":
|
case "Enter":
|
||||||
|
if (ev.ctrlKey || ev.metaKey) {
|
||||||
|
// Open in a new pane
|
||||||
|
dispatch("ctrl-enter", $selectedNote)
|
||||||
|
} else if (ev.shiftKey) {
|
||||||
|
// Create a new note
|
||||||
|
dispatch("shift-enter", $selectedNote)
|
||||||
|
} else {
|
||||||
|
// Open in current pane
|
||||||
dispatch("enter", $selectedNote)
|
dispatch("enter", $selectedNote)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ function getSuggestions(query: string): ResultNote[] {
|
|||||||
return suggestions
|
return suggestions
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onChooseSuggestion(item: ResultNote): Promise<void> {
|
async function openNote(item: ResultNote, newPane = false): Promise<void> {
|
||||||
const file = plugin.app.vault.getAbstractFileByPath(item.path) as TFile
|
const file = plugin.app.vault.getAbstractFileByPath(item.path) as TFile
|
||||||
// const fileCache = this.app.metadataCache.getFileCache(file)
|
// const fileCache = this.app.metadataCache.getFileCache(file)
|
||||||
// console.log(fileCache)
|
// console.log(fileCache)
|
||||||
@@ -89,7 +89,7 @@ async function onChooseSuggestion(item: ResultNote): Promise<void> {
|
|||||||
const offset = content.indexOf(
|
const offset = content.indexOf(
|
||||||
item.matches[item.occurence].match.toLowerCase()
|
item.matches[item.occurence].match.toLowerCase()
|
||||||
)
|
)
|
||||||
await plugin.app.workspace.openLinkText(item.path, "")
|
await plugin.app.workspace.openLinkText(item.path, "", newPane)
|
||||||
|
|
||||||
const view = plugin.app.workspace.getActiveViewOfType(MarkdownView)
|
const view = plugin.app.workspace.getActiveViewOfType(MarkdownView)
|
||||||
if (!view) {
|
if (!view) {
|
||||||
@@ -105,16 +105,47 @@ async function onChooseSuggestion(item: ResultNote): Promise<void> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function openNote(event: CustomEvent<ResultNote>): void {
|
async function createOrOpenNote(item: ResultNote): Promise<void> {
|
||||||
onChooseSuggestion(event.detail)
|
try {
|
||||||
|
const file = await plugin.app.vault.create(
|
||||||
|
$searchQuery + ".md",
|
||||||
|
"# " + $searchQuery
|
||||||
|
)
|
||||||
|
await plugin.app.workspace.openLinkText(file.path, "")
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof Error && e.message === "File already exists.") {
|
||||||
|
// Open the existing file instead of creating it
|
||||||
|
await openNote(item)
|
||||||
|
} else {
|
||||||
|
console.error(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onInputEnter(event: CustomEvent<ResultNote>): void {
|
||||||
|
openNote(event.detail)
|
||||||
|
modal.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
function onInputCtrlEnter(event: CustomEvent<ResultNote>): void {
|
||||||
|
openNote(event.detail, true)
|
||||||
|
modal.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
function onInputShiftEnter(event: CustomEvent<ResultNote>): void {
|
||||||
|
createOrOpenNote(event.detail)
|
||||||
modal.close()
|
modal.close()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<CmpInput on:enter={openNote} />
|
<CmpInput
|
||||||
|
on:enter={onInputEnter}
|
||||||
|
on:shift-enter={onInputShiftEnter}
|
||||||
|
on:ctrl-enter={onInputCtrlEnter}
|
||||||
|
/>
|
||||||
|
|
||||||
<div class="prompt-results">
|
<div class="prompt-results">
|
||||||
{#each $resultNotes as result (result.path)}
|
{#each $resultNotes as result}
|
||||||
<CmpNoteResult selected={result === $selectedNote} note={result} />
|
<CmpNoteResult selected={result === $selectedNote} note={result} />
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user