mirror of
https://github.com/rivea0/obsidian-match-syntax.git
synced 2026-07-22 05:46:49 +00:00
feat: hit return to initiate search (#2)
This commit is contained in:
parent
0c5d06490c
commit
977403ee34
1 changed files with 21 additions and 0 deletions
21
src/modal.ts
21
src/modal.ts
|
|
@ -1,9 +1,23 @@
|
|||
import { App, Modal, Setting } from 'obsidian';
|
||||
import type { KeymapEventHandler } from 'obsidian';
|
||||
|
||||
export class MatchTextModal extends Modal {
|
||||
#keymapEvtHandler: KeymapEventHandler | null = null;
|
||||
constructor(app: App, onSubmit: (textToMatch: string) => void) {
|
||||
super(app);
|
||||
this.setTitle('Enter match syntax: ');
|
||||
this.#keymapEvtHandler = this.scope.register([], 'Enter', (evt: KeyboardEvent) => {
|
||||
if (evt.isComposing) {
|
||||
return;
|
||||
}
|
||||
evt.preventDefault();
|
||||
const findMatchesBtn = document
|
||||
.getElementsByClassName('mod-cta')
|
||||
.item(0) as HTMLButtonElement | null;
|
||||
if (findMatchesBtn) {
|
||||
findMatchesBtn.click();
|
||||
}
|
||||
});
|
||||
|
||||
let matchStr = '';
|
||||
const settingContent = this.contentEl;
|
||||
|
|
@ -28,4 +42,11 @@ export class MatchTextModal extends Modal {
|
|||
})
|
||||
);
|
||||
}
|
||||
|
||||
onClose(): void {
|
||||
if (this.#keymapEvtHandler) {
|
||||
this.scope.unregister(this.#keymapEvtHandler);
|
||||
this.#keymapEvtHandler = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue