#87 - create in a new pane + fixed some settings stuff
This commit is contained in:
@@ -34,9 +34,9 @@
|
||||
searchQuery = searchHistory[historySearchIndex]
|
||||
eventBus.enable('vault')
|
||||
eventBus.on('vault', 'enter', openNoteAndCloseModal)
|
||||
eventBus.on('vault', 'shift-enter', createNoteAndCloseModal)
|
||||
eventBus.on('vault', 'ctrl-enter', openNoteInNewPane)
|
||||
eventBus.on('vault', 'alt-enter', insertLink)
|
||||
eventBus.on('vault', 'create-note', createNoteAndCloseModal)
|
||||
eventBus.on('vault', 'open-in-new-pane', openNoteInNewPane)
|
||||
eventBus.on('vault', 'insert-link', insertLink)
|
||||
eventBus.on('vault', 'tab', switchToInFileModal)
|
||||
eventBus.on('vault', 'arrow-up', () => moveIndex(-1))
|
||||
eventBus.on('vault', 'arrow-down', () => moveIndex(1))
|
||||
@@ -105,9 +105,12 @@
|
||||
openNote(note, newPane)
|
||||
}
|
||||
|
||||
async function createNoteAndCloseModal(): Promise<void> {
|
||||
async function createNoteAndCloseModal(opt?: {
|
||||
newLeaf: boolean
|
||||
}): Promise<void> {
|
||||
console.log(opt)
|
||||
try {
|
||||
await createNote(searchQuery)
|
||||
await createNote(searchQuery, opt?.newLeaf)
|
||||
} catch (e) {
|
||||
new Notice((e as Error).message)
|
||||
return
|
||||
@@ -208,6 +211,7 @@
|
||||
<span class="prompt-instruction-command">↹</span>
|
||||
<span>to switch to In-File Search</span>
|
||||
</div>
|
||||
|
||||
<br />
|
||||
|
||||
<div class="prompt-instruction">
|
||||
@@ -218,17 +222,22 @@
|
||||
<span class="prompt-instruction-command">shift ↵</span>
|
||||
<span>to create</span>
|
||||
</div>
|
||||
<div class="prompt-instruction">
|
||||
<span class="prompt-instruction-command">ctrl shift ↵</span>
|
||||
<span>to create in a new pane</span>
|
||||
</div>
|
||||
|
||||
<br />
|
||||
|
||||
<div class="prompt-instruction">
|
||||
<span class="prompt-instruction-command">alt ↵</span>
|
||||
<span>to insert a link</span>
|
||||
</div>
|
||||
<div class="prompt-instruction">
|
||||
<span class="prompt-instruction-command">esc</span><span>to close</span>
|
||||
</div>
|
||||
<br />
|
||||
|
||||
<div class="prompt-instruction">
|
||||
<span class="prompt-instruction-command">ctrl+h</span><span
|
||||
>to toggle context</span>
|
||||
</div>
|
||||
<div class="prompt-instruction">
|
||||
<span class="prompt-instruction-command">esc</span><span>to close</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -11,6 +11,7 @@ import { eventBus } from './globals'
|
||||
import { registerAPI } from '@vanakat/plugin-api'
|
||||
import api from './api'
|
||||
import { loadSearchHistory } from './search-history'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
// let mainWindow: { on: any; off: any } | null = null
|
||||
// try {
|
||||
@@ -35,7 +36,7 @@ export default class OmnisearchPlugin extends Plugin {
|
||||
|
||||
_registerAPI(this)
|
||||
|
||||
if (settings.ribbonIcon) {
|
||||
if (get(settings).ribbonIcon) {
|
||||
this.addRibbonButton()
|
||||
}
|
||||
|
||||
|
||||
@@ -62,26 +62,35 @@ abstract class OmnisearchModal extends Modal {
|
||||
}
|
||||
|
||||
// #endregion Up/Down navigation
|
||||
|
||||
// Open in new pane
|
||||
this.scope.register(['Mod'], 'Enter', e => {
|
||||
e.preventDefault()
|
||||
eventBus.emit('ctrl-enter') // Open in new pane
|
||||
eventBus.emit('open-in-new-pane')
|
||||
})
|
||||
|
||||
// Insert link
|
||||
this.scope.register(['Alt'], 'Enter', e => {
|
||||
e.preventDefault()
|
||||
eventBus.emit('alt-enter') // Insert link
|
||||
eventBus.emit('insert-link')
|
||||
})
|
||||
|
||||
// Create a new note
|
||||
this.scope.register(['Shift'], 'Enter', e => {
|
||||
e.preventDefault()
|
||||
eventBus.emit('shift-enter') // Create a new note
|
||||
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') // Open in current pane
|
||||
eventBus.emit('enter')
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
23
src/notes.ts
23
src/notes.ts
@@ -1,11 +1,17 @@
|
||||
import { MarkdownView, TFile, type CachedMetadata } from 'obsidian'
|
||||
import {
|
||||
MarkdownView,
|
||||
TFile,
|
||||
WorkspaceLeaf,
|
||||
type CachedMetadata,
|
||||
} from 'obsidian'
|
||||
import {
|
||||
notesCacheFilePath,
|
||||
type IndexedNote,
|
||||
type ResultNote,
|
||||
} from './globals'
|
||||
import { stringsToRegex } from './utils'
|
||||
import { stringsToRegex, wait } from './utils'
|
||||
import { settings } from './settings'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
/**
|
||||
* This is an in-memory cache of the notes, with all their computed fields
|
||||
@@ -20,7 +26,7 @@ export function resetNotesCache(): void {
|
||||
|
||||
export async function loadNotesCache(): Promise<void> {
|
||||
if (
|
||||
settings.storeIndexInFile &&
|
||||
get(settings).storeIndexInFile &&
|
||||
(await app.vault.adapter.exists(notesCacheFilePath))
|
||||
) {
|
||||
try {
|
||||
@@ -93,7 +99,7 @@ export async function openNote(
|
||||
})
|
||||
}
|
||||
|
||||
export async function createNote(name: string): Promise<void> {
|
||||
export async function createNote(name: string, newLeaf = false): Promise<void> {
|
||||
try {
|
||||
let pathPrefix = ''
|
||||
switch (app.vault.getConfig('newFileLocation')) {
|
||||
@@ -107,14 +113,7 @@ export async function createNote(name: string): Promise<void> {
|
||||
pathPrefix = ''
|
||||
break
|
||||
}
|
||||
const file = await app.vault.create(`${pathPrefix}${name}.md`, '')
|
||||
await app.workspace.openLinkText(file.path, '')
|
||||
const view = app.workspace.getActiveViewOfType(MarkdownView)
|
||||
if (!view) {
|
||||
throw new Error('OmniSearch - No active MarkdownView')
|
||||
}
|
||||
const pos = view.editor.offsetToPos(name.length + 5)
|
||||
pos.ch = 0
|
||||
app.workspace.openLinkText(`${pathPrefix}${name}.md`, '', newLeaf)
|
||||
} catch (e) {
|
||||
;(e as any).message =
|
||||
'OmniSearch - Could not create note: ' + (e as any).message
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { get } from 'svelte/store'
|
||||
import { settings } from './settings'
|
||||
import { removeDiacritics, stripSurroundingQuotes } from './utils'
|
||||
import { parseQuery } from './vendor/parse-query'
|
||||
@@ -22,7 +23,7 @@ export class Query {
|
||||
public exclusions: QueryToken[] = []
|
||||
|
||||
constructor(text = '') {
|
||||
if (settings.ignoreDiacritics) text = removeDiacritics(text)
|
||||
if (get(settings).ignoreDiacritics) text = removeDiacritics(text)
|
||||
const tokens = parseQuery(text.toLowerCase(), { tokenize: true })
|
||||
this.exclusions = tokens.exclude.text
|
||||
.map(this.formatToken)
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
wait,
|
||||
} from './utils'
|
||||
import type { Query } from './query'
|
||||
import { settings } from './settings'
|
||||
import { settings as storeSettings } from './settings'
|
||||
import {
|
||||
removeNoteFromCache,
|
||||
getNoteFromCache,
|
||||
@@ -31,10 +31,13 @@ import {
|
||||
saveNotesCacheToFile,
|
||||
isCacheOutdated,
|
||||
} from './notes'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
let minisearchInstance: MiniSearch<IndexedNote>
|
||||
let isIndexChanged: boolean
|
||||
|
||||
const settings = get(storeSettings)
|
||||
|
||||
const tokenize = (text: string): string[] => {
|
||||
const tokens = text.split(SPACE_OR_PUNCTUATION)
|
||||
const chsSegmenter = (app as any).plugins.plugins['cm-chs-patch']
|
||||
@@ -140,6 +143,7 @@ export async function initGlobalSearchIndex(): Promise<void> {
|
||||
*/
|
||||
async function search(query: Query): Promise<SearchResult[]> {
|
||||
if (!query.segmentsToStr()) return []
|
||||
|
||||
let results = minisearchInstance.search(query.segmentsToStr(), {
|
||||
prefix: true,
|
||||
fuzzy: term => (term.length > 4 ? 0.2 : false),
|
||||
|
||||
Reference in New Issue
Block a user