Refactored events to use a small global event bus
This commit is contained in:
35
src/modal.ts
35
src/modal.ts
@@ -1,6 +1,7 @@
|
||||
import { App, Modal, TFile } from 'obsidian'
|
||||
import CmpModalVault from './CmpModalVault.svelte'
|
||||
import CmpModalInFile from './CmpModalInFile.svelte'
|
||||
import { eventBus } from './globals'
|
||||
|
||||
abstract class ModalOmnisearch extends Modal {
|
||||
constructor(app: App) {
|
||||
@@ -12,13 +13,45 @@ abstract class ModalOmnisearch extends Modal {
|
||||
this.modalEl.replaceChildren()
|
||||
this.modalEl.append(closeEl)
|
||||
this.modalEl.addClass('omnisearch-modal', 'prompt')
|
||||
|
||||
this.modalEl.tabIndex = -1
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class ModalVault extends ModalOmnisearch {
|
||||
constructor(app: App) {
|
||||
super(app)
|
||||
|
||||
new CmpModalVault({
|
||||
target: this.modalEl,
|
||||
props: {
|
||||
|
||||
Reference in New Issue
Block a user