Almost there...

This commit is contained in:
Simon Cambier
2022-04-18 22:42:30 +02:00
parent f6c3f9b580
commit dc32bcad5b
6 changed files with 51 additions and 13 deletions

View File

@@ -36,7 +36,7 @@ function moveNoteSelection(ev: KeyboardEvent): void {
// Create a new note
dispatch("shift-enter")
} else if (ev.altKey) {
// Create a new note
// Expand in-note results
dispatch("alt-enter")
} else {
// Open in current pane

View File

@@ -1,11 +1,15 @@
<script lang="ts">
import CmpInput from "./CmpInput.svelte"
import CmpInFileResult from "./CmpInfileResult.svelte"
import CmpResultInFile from "./CmpResultInFile.svelte"
import { excerptAfter, type SearchMatch } from "./globals"
import { modal, plugin, resultNotes } from "./stores"
import { loopIndex } from "./utils"
import { tick } from "svelte"
import { MarkdownView } from "obsidian"
import CmpModalVault from "./CmpModalVault.svelte"
import { OmnisearchModal } from "./modal"
export let canGoBack = false
let matches: SearchMatch[] = []
let groupedOffsets: number[] = []
@@ -23,6 +27,15 @@ $: {
// console.log(groupedOffsets)
}
}
$: {
if (canGoBack) {
$modal.onClose = () => {
if (canGoBack) {
new OmnisearchModal($plugin).open()
}
}
}
}
/**
* Group together close
@@ -95,7 +108,7 @@ function openSelection(): void {
<div class="prompt-results">
{#if groupedOffsets.length && note}
{#each groupedOffsets as offset, i}
<CmpInFileResult
<CmpResultInFile
{offset}
{note}
index={i}
@@ -117,6 +130,11 @@ function openSelection(): void {
<span class="prompt-instruction-command"></span><span>to open</span>
</div>
<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>

View File

@@ -1,8 +1,10 @@
<script lang="ts">
import { TFile } from "obsidian"
import { tick } from "svelte"
import CmpInput from "./CmpInput.svelte"
import CmpNoteResult from "./CmpNoteResult.svelte"
import CmpResultNote from "./CmpResultNote.svelte"
import type { ResultNote } from "./globals"
import { OmnisearchModal } from "./modal"
import { openNote } from "./notes"
import { modal, plugin, resultNotes, searchQuery } from "./stores"
import { loopIndex } from "./utils"
@@ -36,22 +38,32 @@ function onClick() {
$modal.close()
}
function onInputEnter(event: CustomEvent<unknown>): void {
function onInputEnter(): void {
// console.log(event.detail)
openNote(selectedNote)
$modal.close()
}
function onInputCtrlEnter(event: CustomEvent<unknown>): void {
function onInputCtrlEnter(): void {
openNote(selectedNote, true)
$modal.close()
}
function onInputShiftEnter(event: CustomEvent<unknown>): void {
function onInputShiftEnter(): void {
createOrOpenNote(selectedNote)
$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 {
selectedIndex = loopIndex(selectedIndex + dir, $resultNotes.length)
scrollIntoView()
@@ -74,6 +86,7 @@ function scrollIntoView(): void {
on:enter={onInputEnter}
on:shift-enter={onInputShiftEnter}
on:ctrl-enter={onInputCtrlEnter}
on:alt-enter={onInputAltEnter}
on:arrow-up={() => moveIndex(-1)}
on:arrow-down={() => moveIndex(1)}
/>
@@ -81,7 +94,7 @@ function scrollIntoView(): void {
<div class="modal-content">
<div class="prompt-results">
{#each $resultNotes as result, i}
<CmpNoteResult
<CmpResultNote
selected={i === selectedIndex}
note={result}
on:hover={(e) => (selectedIndex = i)}
@@ -94,6 +107,11 @@ function scrollIntoView(): void {
<div class="prompt-instruction">
<span class="prompt-instruction-command">↑↓</span><span>to navigate</span>
</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">
<span class="prompt-instruction-command"></span><span>to open</span>
</div>

View File

@@ -34,7 +34,6 @@ function cleanContent(content: string): string {
on:click={(e) => dispatch("click")}
>
<span class="omnisearch-result__title">
<!-- {@html note.basename.replace(reg, highlighter)} -->
{@html note.basename}
</span>

View File

@@ -1,11 +1,11 @@
import { Modal, TFile } from 'obsidian'
import type OmnisearchPlugin from './main'
import CmpModalVault from './CmpModalVault.svelte'
import CmpModalFile from './CmpModalFile.svelte'
import CmpModalInFile from './CmpModalInFile.svelte'
import { inFileSearch, modal } from './stores'
export class OmnisearchModal extends Modal {
constructor(plugin: OmnisearchPlugin, file?: TFile) {
constructor(plugin: OmnisearchPlugin, file?: TFile, canGoBack = false) {
super(plugin.app)
// Remove all the default modal's children (except the close button)
@@ -19,8 +19,11 @@ export class OmnisearchModal extends Modal {
modal.set(this)
if (file) {
new CmpModalFile({
new CmpModalInFile({
target: this.modalEl,
props: {
canGoBack,
},
})
}
else {