feat: hit return to initiate search (#2)

This commit is contained in:
rivea0 2025-07-13 14:22:48 +03:00
parent 0c5d06490c
commit 977403ee34

View file

@ -1,9 +1,23 @@
import { App, Modal, Setting } from 'obsidian'; import { App, Modal, Setting } from 'obsidian';
import type { KeymapEventHandler } from 'obsidian';
export class MatchTextModal extends Modal { export class MatchTextModal extends Modal {
#keymapEvtHandler: KeymapEventHandler | null = null;
constructor(app: App, onSubmit: (textToMatch: string) => void) { constructor(app: App, onSubmit: (textToMatch: string) => void) {
super(app); super(app);
this.setTitle('Enter match syntax: '); 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 = ''; let matchStr = '';
const settingContent = this.contentEl; 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;
}
}
} }