Squashed commit of the following:

commit ac82511ddd17d5472ae3cfea9bbad9754f5a4d62
Author: Simon Cambier <simon.cambier@protonmail.com>
Date:   Sat Oct 22 08:23:42 2022 +0200

    Screw that cache, seriously.

commit 8ba40d1be73daaaffea09e07bc56c339266db9b6
Author: Simon Cambier <simon.cambier@protonmail.com>
Date:   Fri Oct 21 22:36:48 2022 +0200

    Stuff

commit 27b8fd7dc809be9714a109d3a458eb1276a47e2e
Author: Simon Cambier <simon.cambier@protonmail.com>
Date:   Fri Oct 21 22:22:20 2022 +0200

    Moved files

commit fb1349c914907e586e103ca54fb04b9ddd45ef5d
Author: Simon Cambier <simon.cambier@protonmail.com>
Date:   Thu Oct 20 22:25:29 2022 +0200

    Removed duplicate code

commit e7371138e60cbe4155cfd4fb44e3ee1d2e3ee088
Author: Simon Cambier <simon.cambier@protonmail.com>
Date:   Thu Oct 20 21:50:09 2022 +0200

    Moved a bunch of files

commit 2ee1b2a0e799d4b41ab3a444d8cc44dfff5b5623
Author: Simon Cambier <simon.cambier@protonmail.com>
Date:   Thu Oct 20 21:32:21 2022 +0200

    Removed useless code

commit 76c530dfb9adbad1bbe9079de2330fe43a044249
Author: Simon Cambier <simon.cambier@protonmail.com>
Date:   Thu Oct 20 20:44:11 2022 +0200

    Split file reading and indexing
This commit is contained in:
Simon Cambier
2022-10-22 08:25:34 +02:00
parent 1376cea282
commit c2ecdd79ad
25 changed files with 338 additions and 403 deletions

View File

@@ -10,16 +10,16 @@
type ResultNote,
type SearchMatch,
} from 'src/globals'
import { loopIndex } from 'src/utils'
import { loopIndex } from 'src/tools/utils'
import { onDestroy, onMount, tick } from 'svelte'
import { MarkdownView } from 'obsidian'
import * as Search from 'src/search'
import * as Search from 'src/search/search'
import ModalContainer from './ModalContainer.svelte'
import { OmnisearchInFileModal, OmnisearchVaultModal } from 'src/modals'
import { OmnisearchInFileModal, OmnisearchVaultModal } from 'src/components/modals'
import ResultItemInFile from './ResultItemInFile.svelte'
import { Query } from 'src/query'
import { openNote } from 'src/notes'
import { saveSearchHistory } from '../search-history'
import { Query } from 'src/search/query'
import { openNote } from 'src/tools/notes'
import { saveSearchHistory } from '../search/search-history'
export let modal: OmnisearchInFileModal
export let parent: OmnisearchVaultModal | null = null

View File

@@ -4,13 +4,13 @@
import InputSearch from './InputSearch.svelte'
import ModalContainer from './ModalContainer.svelte'
import { eventBus, type ResultNote } from 'src/globals'
import { createNote, openNote } from 'src/notes'
import * as Search from 'src/search'
import { getCtrlKeyLabel, getExtension, loopIndex } from 'src/utils'
import { OmnisearchInFileModal, type OmnisearchVaultModal } from 'src/modals'
import { createNote, openNote } from 'src/tools/notes'
import * as Search from 'src/search/search'
import { getCtrlKeyLabel, getExtension, loopIndex } from 'src/tools/utils'
import { OmnisearchInFileModal, type OmnisearchVaultModal } from 'src/components/modals'
import ResultItemVault from './ResultItemVault.svelte'
import { Query } from 'src/query'
import { saveSearchHistory, searchHistory } from 'src/search-history'
import { Query } from 'src/search/query'
import { saveSearchHistory, searchHistory } from 'src/search/search-history'
import { settings } from '../settings'
import * as NotesIndex from '../notes-index'

View File

@@ -1,6 +1,6 @@
<script lang="ts">
import type { ResultNote } from '../globals'
import { highlighter, makeExcerpt, stringsToRegex } from '../utils'
import { highlighter, makeExcerpt, stringsToRegex } from '../tools/utils'
import ResultItemContainer from './ResultItemContainer.svelte'
export let offset: number

View File

@@ -2,7 +2,7 @@
import { cacheManager } from 'src/cache-manager'
import { settings, showExcerpt } from 'src/settings'
import type { ResultNote } from '../globals'
import { highlighter, makeExcerpt, stringsToRegex } from '../utils'
import { highlighter, makeExcerpt, stringsToRegex } from '../tools/utils'
import ResultItemContainer from './ResultItemContainer.svelte'
export let selected = false
@@ -10,7 +10,7 @@
$: reg = stringsToRegex(note.foundWords)
$: cleanedContent = makeExcerpt(note.content, note.matches[0]?.offset ?? -1)
$: glyph = cacheManager.getNoteFromMemCache(note.path)?.doesNotExist
$: glyph = cacheManager.getDocument(note.path)?.doesNotExist
$: title = settings.showShortName ? note.basename : note.path
</script>

167
src/components/modals.ts Normal file
View File

@@ -0,0 +1,167 @@
import { App, Modal, TFile } from 'obsidian'
import ModalVault from './ModalVault.svelte'
import ModalInFile from './ModalInFile.svelte'
import {eventBus, EventNames, isInputComposition} from '../globals'
import { settings } from '../settings'
abstract class OmnisearchModal extends Modal {
protected constructor(app: App) {
super(app)
// Remove all the default modal's children
// so that we can more easily customize it
// const closeEl = this.containerEl.find('.modal-close-button')
this.modalEl.replaceChildren()
// this.modalEl.append(closeEl)
this.modalEl.addClass('omnisearch-modal', 'prompt')
// this.modalEl.removeClass('modal')
this.modalEl.tabIndex = -1
// Setup events that can be listened through the event bus
// #region Up/Down navigation
this.scope.register([], 'ArrowDown', e => {
e.preventDefault()
eventBus.emit('arrow-down')
})
this.scope.register([], 'ArrowUp', e => {
e.preventDefault()
eventBus.emit('arrow-up')
})
// Ctrl+j/k
for (const key of [
{ k: 'j', dir: 'down' },
{ k: 'k', dir: 'up' },
] as const) {
for (const modifier of ['Ctrl', 'Meta'] as const) {
this.scope.register([modifier], key.k, e => {
if (settings.CtrlJK && this.app.vault.getConfig('vimMode')) {
e.preventDefault()
eventBus.emit('arrow-' + key.dir)
}
})
}
}
// Ctrl+n/p
for (const key of [
{ k: 'n', dir: 'down' },
{ k: 'p', dir: 'up' },
] as const) {
for (const modifier of ['Ctrl', 'Meta'] as const) {
this.scope.register([modifier], key.k, e => {
if (settings.CtrlNP && this.app.vault.getConfig('vimMode')) {
e.preventDefault()
eventBus.emit('arrow-' + key.dir)
}
})
}
}
// #endregion Up/Down navigation
// Open in new pane
this.scope.register(['Mod'], 'Enter', e => {
e.preventDefault()
eventBus.emit('open-in-new-pane')
})
// Insert link
this.scope.register(['Alt'], 'Enter', e => {
e.preventDefault()
eventBus.emit('insert-link')
})
// Create a new note
this.scope.register(['Shift'], 'Enter', e => {
e.preventDefault()
eventBus.emit('create-note')
})
this.scope.register(['Ctrl', 'Shift'], 'Enter', e => {
e.preventDefault()
eventBus.emit('create-note', { newLeaf: true })
})
// Open in current pane
this.scope.register([], 'Enter', e => {
if (!isInputComposition()) {
// Check if the user is still typing
e.preventDefault()
eventBus.emit('enter')
}
})
this.scope.register([], 'Tab', e => {
e.preventDefault()
eventBus.emit('tab') // Switch context
})
// Search history
this.scope.register(['Alt'], 'ArrowDown', e => {
e.preventDefault()
eventBus.emit('next-search-history')
})
this.scope.register(['Alt'], 'ArrowUp', e => {
e.preventDefault()
eventBus.emit('prev-search-history')
})
// Context
this.scope.register(['Ctrl'], 'h', e => {
e.preventDefault()
eventBus.emit(EventNames.ToggleExcerpts)
})
}
}
export class OmnisearchVaultModal extends OmnisearchModal {
constructor(app: App) {
super(app)
const cmp = new ModalVault({
target: this.modalEl,
props: {
modal: this,
},
})
this.onClose = () => {
// Since the component is manually created,
// we also need to manually destroy it
cmp.$destroy()
}
}
}
export class OmnisearchInFileModal extends OmnisearchModal {
constructor(
app: App,
file: TFile,
searchQuery: string = '',
parent?: OmnisearchModal
) {
super(app)
const cmp = new ModalInFile({
target: this.modalEl,
props: {
modal: this,
singleFilePath: file.path,
parent: parent,
searchQuery,
},
})
if (parent) {
// Hide the parent vault modal, and show it back when this one is closed
parent.containerEl.toggleVisibility(false)
}
this.onClose = () => {
if (parent) {
parent.containerEl.toggleVisibility(true)
}
cmp.$destroy()
}
}
}