Removed modal from stores
This commit is contained in:
@@ -2,17 +2,21 @@
|
|||||||
import CmpInput from "./CmpInput.svelte"
|
import CmpInput from "./CmpInput.svelte"
|
||||||
import CmpResultInFile from "./CmpResultInFile.svelte"
|
import CmpResultInFile from "./CmpResultInFile.svelte"
|
||||||
import { excerptAfter, type ResultNote, type SearchMatch } from "./globals"
|
import { excerptAfter, type ResultNote, type SearchMatch } from "./globals"
|
||||||
import { modal, plugin } from "./stores"
|
import { plugin } 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 { getSuggestions } from "./search"
|
import { getSuggestions } from "./search"
|
||||||
|
import type { OmnisearchModal } from "./modal"
|
||||||
|
|
||||||
|
export let modal: OmnisearchModal
|
||||||
|
export let parent: OmnisearchModal | null = null
|
||||||
export let canGoBack = false
|
export let canGoBack = false
|
||||||
export let singleFilePath = ""
|
export let singleFilePath = ""
|
||||||
|
let searchQuery: string
|
||||||
|
|
||||||
let groupedOffsets: number[] = []
|
let groupedOffsets: number[] = []
|
||||||
let selectedIndex = 0
|
let selectedIndex = 0
|
||||||
let searchQuery: string
|
|
||||||
let note: ResultNote | null = null
|
let note: ResultNote | null = null
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
@@ -71,14 +75,18 @@ function scrollIntoView(): void {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function openSelection(): void {
|
async function openSelection(): Promise<void> {
|
||||||
// TODO: clean me, merge with notes.openNote()
|
// TODO: clean me, merge with notes.openNote()
|
||||||
if (note) {
|
if (note) {
|
||||||
$plugin.app.workspace.openLinkText(note.path, "")
|
modal.close()
|
||||||
|
if (parent) parent.close()
|
||||||
|
|
||||||
|
await $plugin.app.workspace.openLinkText(note.path, "")
|
||||||
const view = $plugin.app.workspace.getActiveViewOfType(MarkdownView)
|
const view = $plugin.app.workspace.getActiveViewOfType(MarkdownView)
|
||||||
if (!view) {
|
if (!view) {
|
||||||
throw new Error("OmniSearch - No active MarkdownView")
|
throw new Error("OmniSearch - No active MarkdownView")
|
||||||
}
|
}
|
||||||
|
|
||||||
const offset = groupedOffsets[selectedIndex] ?? 0
|
const offset = groupedOffsets[selectedIndex] ?? 0
|
||||||
const pos = view.editor.offsetToPos(offset)
|
const pos = view.editor.offsetToPos(offset)
|
||||||
pos.ch = 0
|
pos.ch = 0
|
||||||
@@ -87,7 +95,6 @@ function openSelection(): void {
|
|||||||
from: { line: pos.line - 10, ch: 0 },
|
from: { line: pos.line - 10, ch: 0 },
|
||||||
to: { line: pos.line + 10, ch: 0 },
|
to: { line: pos.line + 10, ch: 0 },
|
||||||
})
|
})
|
||||||
$modal.close()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -11,9 +11,10 @@ import type { ResultNote } from "./globals"
|
|||||||
import { OmnisearchModal } from "./modal"
|
import { OmnisearchModal } from "./modal"
|
||||||
import { openNote } from "./notes"
|
import { openNote } from "./notes"
|
||||||
import { getSuggestions } from "./search"
|
import { getSuggestions } from "./search"
|
||||||
import { modal, plugin } from "./stores"
|
import { plugin } from "./stores"
|
||||||
import { loopIndex } from "./utils"
|
import { loopIndex } from "./utils"
|
||||||
|
|
||||||
|
export let modal: OmnisearchModal
|
||||||
let selectedIndex = 0
|
let selectedIndex = 0
|
||||||
let searchQuery: string
|
let searchQuery: string
|
||||||
let resultNotes: ResultNote[] = []
|
let resultNotes: ResultNote[] = []
|
||||||
@@ -53,34 +54,34 @@ async function createOrOpenNote(item: ResultNote): Promise<void> {
|
|||||||
function onClick() {
|
function onClick() {
|
||||||
if (!selectedNote) return
|
if (!selectedNote) return
|
||||||
openNote(selectedNote)
|
openNote(selectedNote)
|
||||||
$modal.close()
|
modal.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
function onInputEnter(): void {
|
function onInputEnter(): void {
|
||||||
// console.log(event.detail)
|
// console.log(event.detail)
|
||||||
if (!selectedNote) return
|
if (!selectedNote) return
|
||||||
openNote(selectedNote)
|
openNote(selectedNote)
|
||||||
$modal.close()
|
modal.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
function onInputCtrlEnter(): void {
|
function onInputCtrlEnter(): void {
|
||||||
if (!selectedNote) return
|
if (!selectedNote) return
|
||||||
openNote(selectedNote, true)
|
openNote(selectedNote, true)
|
||||||
$modal.close()
|
modal.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
function onInputShiftEnter(): void {
|
function onInputShiftEnter(): void {
|
||||||
if (!selectedNote) return
|
if (!selectedNote) return
|
||||||
createOrOpenNote(selectedNote)
|
createOrOpenNote(selectedNote)
|
||||||
$modal.close()
|
modal.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
function onInputAltEnter(): void {
|
function onInputAltEnter(): void {
|
||||||
if (selectedNote) {
|
if (selectedNote) {
|
||||||
const file = $plugin.app.vault.getAbstractFileByPath(selectedNote.path)
|
const file = $plugin.app.vault.getAbstractFileByPath(selectedNote.path)
|
||||||
if (file && file instanceof TFile) {
|
if (file && file instanceof TFile) {
|
||||||
// $modal.close()
|
// modal.close()
|
||||||
new OmnisearchModal($plugin, file, true).open()
|
new OmnisearchModal($plugin, file, true, modal).open()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
15
src/modal.ts
15
src/modal.ts
@@ -2,10 +2,14 @@ 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 CmpModalInFile from './CmpModalInFile.svelte'
|
import CmpModalInFile from './CmpModalInFile.svelte'
|
||||||
import { modal } from './stores'
|
|
||||||
|
|
||||||
export class OmnisearchModal extends Modal {
|
export class OmnisearchModal extends Modal {
|
||||||
constructor(plugin: OmnisearchPlugin, file?: TFile, canGoBack = false) {
|
constructor(
|
||||||
|
plugin: OmnisearchPlugin,
|
||||||
|
file?: TFile,
|
||||||
|
canGoBack = false,
|
||||||
|
parent?: OmnisearchModal,
|
||||||
|
) {
|
||||||
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)
|
||||||
@@ -15,20 +19,23 @@ export class OmnisearchModal extends Modal {
|
|||||||
this.modalEl.append(closeEl)
|
this.modalEl.append(closeEl)
|
||||||
this.modalEl.addClass('omnisearch-modal', 'prompt')
|
this.modalEl.addClass('omnisearch-modal', 'prompt')
|
||||||
|
|
||||||
modal.set(this)
|
|
||||||
|
|
||||||
if (file) {
|
if (file) {
|
||||||
new CmpModalInFile({
|
new CmpModalInFile({
|
||||||
target: this.modalEl,
|
target: this.modalEl,
|
||||||
props: {
|
props: {
|
||||||
|
modal: this,
|
||||||
canGoBack,
|
canGoBack,
|
||||||
singleFilePath: file.path,
|
singleFilePath: file.path,
|
||||||
|
parent: parent,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
new CmpModalVault({
|
new CmpModalVault({
|
||||||
target: this.modalEl,
|
target: this.modalEl,
|
||||||
|
props: {
|
||||||
|
modal: this,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import type { TFile } from 'obsidian'
|
|
||||||
import { get, writable } from 'svelte/store'
|
import { get, writable } from 'svelte/store'
|
||||||
import type { IndexedNote, ResultNote } from './globals'
|
import type { IndexedNote } from './globals'
|
||||||
import type OmnisearchPlugin from './main'
|
import type OmnisearchPlugin from './main'
|
||||||
import type { OmnisearchModal } from './modal'
|
|
||||||
|
|
||||||
function createIndexedNotes() {
|
function createIndexedNotes() {
|
||||||
const { subscribe, set, update } = writable<Record<string, IndexedNote>>({})
|
const { subscribe, set, update } = writable<Record<string, IndexedNote>>({})
|
||||||
@@ -32,11 +30,6 @@ function createIndexedNotes() {
|
|||||||
*/
|
*/
|
||||||
export const plugin = writable<OmnisearchPlugin>()
|
export const plugin = writable<OmnisearchPlugin>()
|
||||||
|
|
||||||
/**
|
|
||||||
* A reference to the modal instance
|
|
||||||
*/
|
|
||||||
export const modal = writable<OmnisearchModal>()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The entire list of indexed notes, constantly kept up-to-date.
|
* The entire list of indexed notes, constantly kept up-to-date.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user