Merge branch 'master' into feature/25-search-filters

This commit is contained in:
Simon Cambier
2022-04-28 19:35:00 +02:00
8 changed files with 53 additions and 53 deletions

View File

@@ -28,7 +28,9 @@ let selectedIndex = 0
let note: ResultNote | null = null
onMount(() => {
searchQuery = lastSearch
if (lastSearch && !searchQuery) {
searchQuery = lastSearch
}
eventBus.disable("vault")
eventBus.on("infile", "enter", openSelection)
@@ -61,7 +63,7 @@ $: {
}
/**
* Group together close
* Group together close matches to reduce the number of results
*/
function getGroups(matches: SearchMatch[]): SearchMatch[][] {
const groups: SearchMatch[][] = []

View File

@@ -1,4 +1,4 @@
import { MarkdownView, Plugin, TFile } from 'obsidian'
import { Notice, Plugin, TFile } from 'obsidian'
import {
addToIndex,
initGlobalSearchIndex,
@@ -9,6 +9,8 @@ import { OmnisearchInFileModal, OmnisearchVaultModal } from './modals'
export default class OmnisearchPlugin extends Plugin {
async onload(): Promise<void> {
warningOldVersion()
// Commands to display Omnisearch modals
this.addCommand({
id: 'show-modal',
@@ -21,16 +23,8 @@ export default class OmnisearchPlugin extends Plugin {
this.addCommand({
id: 'show-modal-infile',
name: 'In-file search',
checkCallback: (checking: boolean) => {
// Can only be shown when a note is active
const view = app.workspace.getActiveViewOfType(MarkdownView)
if (view) {
if (!checking) {
new OmnisearchInFileModal(app, view.file).open()
}
return true
}
return false
editorCallback: (_editor, view) => {
new OmnisearchInFileModal(app, view.file).open()
},
})
@@ -65,3 +59,16 @@ export default class OmnisearchPlugin extends Plugin {
})
}
}
function warningOldVersion(): void {
const plugins = ((app as any).plugins?.plugins ?? {}) as Record<string, any>
if (plugins['scambier.omnisearch']) {
new Notice(
`OMNISEARCH
It looks like you have 2 versions of Omnisearch installed.
Please uninstall the old one (up to 0.2.5) and keep the new one (1.0.0+)
(Click to dismiss)`,
0,
)
}
}

View File

@@ -17,37 +17,27 @@ abstract class OmnisearchModal extends Modal {
this.modalEl.tabIndex = -1
// Setup events that can be listened through the event bus
this.modalEl.onkeydown = ev => {
switch (ev.key) {
case 'ArrowDown':
ev.preventDefault()
eventBus.emit('arrow-down')
break
case 'ArrowUp':
ev.preventDefault()
eventBus.emit('arrow-up')
break
case 'Enter':
ev.preventDefault()
if (ev.ctrlKey || ev.metaKey) {
// Open in a new pane
eventBus.emit('ctrl-enter')
}
else if (ev.shiftKey) {
// Create a new note
eventBus.emit('shift-enter')
}
else if (ev.altKey) {
// Expand in-note results
eventBus.emit('alt-enter')
}
else {
// Open in current pane
eventBus.emit('enter')
}
break
}
}
this.scope.register([], 'ArrowDown', () => {
eventBus.emit('arrow-down')
})
this.scope.register([], 'ArrowUp', () => {
eventBus.emit('arrow-up')
})
this.scope.register(['Ctrl'], 'Enter', () => {
eventBus.emit('ctrl-enter') // Open in new pane
})
this.scope.register(['Meta'], 'Enter', () => {
eventBus.emit('ctrl-enter') // Open in new pane (but on Mac)
})
this.scope.register(['Alt'], 'Enter', () => {
eventBus.emit('alt-enter') // Open the InFile modal
})
this.scope.register(['Shift'], 'Enter', () => {
eventBus.emit('shift-enter') // Create a new note
})
this.scope.register([], 'Enter', () => {
eventBus.emit('enter') // Open in current pane
})
}
}