Almost there...
This commit is contained in:
@@ -36,7 +36,7 @@ function moveNoteSelection(ev: KeyboardEvent): void {
|
|||||||
// Create a new note
|
// Create a new note
|
||||||
dispatch("shift-enter")
|
dispatch("shift-enter")
|
||||||
} else if (ev.altKey) {
|
} else if (ev.altKey) {
|
||||||
// Create a new note
|
// Expand in-note results
|
||||||
dispatch("alt-enter")
|
dispatch("alt-enter")
|
||||||
} else {
|
} else {
|
||||||
// Open in current pane
|
// Open in current pane
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import CmpInput from "./CmpInput.svelte"
|
import CmpInput from "./CmpInput.svelte"
|
||||||
import CmpInFileResult from "./CmpInfileResult.svelte"
|
import CmpResultInFile from "./CmpResultInFile.svelte"
|
||||||
import { excerptAfter, type SearchMatch } from "./globals"
|
import { excerptAfter, type SearchMatch } from "./globals"
|
||||||
import { modal, plugin, resultNotes } from "./stores"
|
import { modal, plugin, resultNotes } from "./stores"
|
||||||
import { loopIndex } from "./utils"
|
import { loopIndex } from "./utils"
|
||||||
import { tick } from "svelte"
|
import { tick } from "svelte"
|
||||||
import { MarkdownView } from "obsidian"
|
import { MarkdownView } from "obsidian"
|
||||||
|
import CmpModalVault from "./CmpModalVault.svelte"
|
||||||
|
import { OmnisearchModal } from "./modal"
|
||||||
|
|
||||||
|
export let canGoBack = false
|
||||||
|
|
||||||
let matches: SearchMatch[] = []
|
let matches: SearchMatch[] = []
|
||||||
let groupedOffsets: number[] = []
|
let groupedOffsets: number[] = []
|
||||||
@@ -23,6 +27,15 @@ $: {
|
|||||||
// console.log(groupedOffsets)
|
// console.log(groupedOffsets)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$: {
|
||||||
|
if (canGoBack) {
|
||||||
|
$modal.onClose = () => {
|
||||||
|
if (canGoBack) {
|
||||||
|
new OmnisearchModal($plugin).open()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Group together close
|
* Group together close
|
||||||
@@ -95,7 +108,7 @@ function openSelection(): void {
|
|||||||
<div class="prompt-results">
|
<div class="prompt-results">
|
||||||
{#if groupedOffsets.length && note}
|
{#if groupedOffsets.length && note}
|
||||||
{#each groupedOffsets as offset, i}
|
{#each groupedOffsets as offset, i}
|
||||||
<CmpInFileResult
|
<CmpResultInFile
|
||||||
{offset}
|
{offset}
|
||||||
{note}
|
{note}
|
||||||
index={i}
|
index={i}
|
||||||
@@ -117,6 +130,11 @@ function openSelection(): void {
|
|||||||
<span class="prompt-instruction-command">↵</span><span>to open</span>
|
<span class="prompt-instruction-command">↵</span><span>to open</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="prompt-instruction">
|
<div class="prompt-instruction">
|
||||||
<span class="prompt-instruction-command">esc</span><span>to dismiss</span>
|
<span class="prompt-instruction-command">esc</span>
|
||||||
|
{#if canGoBack}
|
||||||
|
<span>to go back to Vault Search</span>
|
||||||
|
{:else}
|
||||||
|
<span>to dismiss</span>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { TFile } from "obsidian"
|
||||||
import { tick } from "svelte"
|
import { tick } from "svelte"
|
||||||
import CmpInput from "./CmpInput.svelte"
|
import CmpInput from "./CmpInput.svelte"
|
||||||
import CmpNoteResult from "./CmpNoteResult.svelte"
|
import CmpResultNote from "./CmpResultNote.svelte"
|
||||||
import type { ResultNote } from "./globals"
|
import type { ResultNote } from "./globals"
|
||||||
|
import { OmnisearchModal } from "./modal"
|
||||||
import { openNote } from "./notes"
|
import { openNote } from "./notes"
|
||||||
import { modal, plugin, resultNotes, searchQuery } from "./stores"
|
import { modal, plugin, resultNotes, searchQuery } from "./stores"
|
||||||
import { loopIndex } from "./utils"
|
import { loopIndex } from "./utils"
|
||||||
@@ -36,22 +38,32 @@ function onClick() {
|
|||||||
$modal.close()
|
$modal.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
function onInputEnter(event: CustomEvent<unknown>): void {
|
function onInputEnter(): void {
|
||||||
// console.log(event.detail)
|
// console.log(event.detail)
|
||||||
openNote(selectedNote)
|
openNote(selectedNote)
|
||||||
$modal.close()
|
$modal.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
function onInputCtrlEnter(event: CustomEvent<unknown>): void {
|
function onInputCtrlEnter(): void {
|
||||||
openNote(selectedNote, true)
|
openNote(selectedNote, true)
|
||||||
$modal.close()
|
$modal.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
function onInputShiftEnter(event: CustomEvent<unknown>): void {
|
function onInputShiftEnter(): void {
|
||||||
createOrOpenNote(selectedNote)
|
createOrOpenNote(selectedNote)
|
||||||
$modal.close()
|
$modal.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onInputAltEnter(): void {
|
||||||
|
if (selectedNote) {
|
||||||
|
const file = $plugin.app.vault.getAbstractFileByPath(selectedNote.path)
|
||||||
|
if (file && file instanceof TFile) {
|
||||||
|
// $modal.close()
|
||||||
|
new OmnisearchModal($plugin, file, true).open()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function moveIndex(dir: 1 | -1): void {
|
function moveIndex(dir: 1 | -1): void {
|
||||||
selectedIndex = loopIndex(selectedIndex + dir, $resultNotes.length)
|
selectedIndex = loopIndex(selectedIndex + dir, $resultNotes.length)
|
||||||
scrollIntoView()
|
scrollIntoView()
|
||||||
@@ -74,6 +86,7 @@ function scrollIntoView(): void {
|
|||||||
on:enter={onInputEnter}
|
on:enter={onInputEnter}
|
||||||
on:shift-enter={onInputShiftEnter}
|
on:shift-enter={onInputShiftEnter}
|
||||||
on:ctrl-enter={onInputCtrlEnter}
|
on:ctrl-enter={onInputCtrlEnter}
|
||||||
|
on:alt-enter={onInputAltEnter}
|
||||||
on:arrow-up={() => moveIndex(-1)}
|
on:arrow-up={() => moveIndex(-1)}
|
||||||
on:arrow-down={() => moveIndex(1)}
|
on:arrow-down={() => moveIndex(1)}
|
||||||
/>
|
/>
|
||||||
@@ -81,7 +94,7 @@ function scrollIntoView(): void {
|
|||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="prompt-results">
|
<div class="prompt-results">
|
||||||
{#each $resultNotes as result, i}
|
{#each $resultNotes as result, i}
|
||||||
<CmpNoteResult
|
<CmpResultNote
|
||||||
selected={i === selectedIndex}
|
selected={i === selectedIndex}
|
||||||
note={result}
|
note={result}
|
||||||
on:hover={(e) => (selectedIndex = i)}
|
on:hover={(e) => (selectedIndex = i)}
|
||||||
@@ -94,6 +107,11 @@ function scrollIntoView(): void {
|
|||||||
<div class="prompt-instruction">
|
<div class="prompt-instruction">
|
||||||
<span class="prompt-instruction-command">↑↓</span><span>to navigate</span>
|
<span class="prompt-instruction-command">↑↓</span><span>to navigate</span>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="prompt-instruction">
|
||||||
|
<span class="prompt-instruction-command">alt ↵</span>
|
||||||
|
<span>to expand in-note results</span>
|
||||||
|
</div>
|
||||||
|
<br />
|
||||||
<div class="prompt-instruction">
|
<div class="prompt-instruction">
|
||||||
<span class="prompt-instruction-command">↵</span><span>to open</span>
|
<span class="prompt-instruction-command">↵</span><span>to open</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ function cleanContent(content: string): string {
|
|||||||
on:click={(e) => dispatch("click")}
|
on:click={(e) => dispatch("click")}
|
||||||
>
|
>
|
||||||
<span class="omnisearch-result__title">
|
<span class="omnisearch-result__title">
|
||||||
<!-- {@html note.basename.replace(reg, highlighter)} -->
|
|
||||||
{@html note.basename}
|
{@html note.basename}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
import { Modal, TFile } from 'obsidian'
|
import { Modal, TFile } from 'obsidian'
|
||||||
import type OmnisearchPlugin from './main'
|
import type OmnisearchPlugin from './main'
|
||||||
import CmpModalVault from './CmpModalVault.svelte'
|
import CmpModalVault from './CmpModalVault.svelte'
|
||||||
import CmpModalFile from './CmpModalFile.svelte'
|
import CmpModalInFile from './CmpModalInFile.svelte'
|
||||||
import { inFileSearch, modal } from './stores'
|
import { inFileSearch, modal } from './stores'
|
||||||
|
|
||||||
export class OmnisearchModal extends Modal {
|
export class OmnisearchModal extends Modal {
|
||||||
constructor(plugin: OmnisearchPlugin, file?: TFile) {
|
constructor(plugin: OmnisearchPlugin, file?: TFile, canGoBack = false) {
|
||||||
super(plugin.app)
|
super(plugin.app)
|
||||||
|
|
||||||
// Remove all the default modal's children (except the close button)
|
// Remove all the default modal's children (except the close button)
|
||||||
@@ -19,8 +19,11 @@ export class OmnisearchModal extends Modal {
|
|||||||
modal.set(this)
|
modal.set(this)
|
||||||
|
|
||||||
if (file) {
|
if (file) {
|
||||||
new CmpModalFile({
|
new CmpModalInFile({
|
||||||
target: this.modalEl,
|
target: this.modalEl,
|
||||||
|
props: {
|
||||||
|
canGoBack,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
Reference in New Issue
Block a user