diff --git a/src/floatSearchIndex.ts b/src/floatSearchIndex.ts index 6a10cd2..0001cbb 100644 --- a/src/floatSearchIndex.ts +++ b/src/floatSearchIndex.ts @@ -1629,6 +1629,9 @@ class FloatSearchModal extends Modal { } inputEl.focus(); inputEl.onkeydown = (e) => { + if (e.isComposing || e.key === "Process" || e.keyCode === 229) { + return; + } const currentView = this.searchLeaf.view as SearchView; switch (e.key) { case "ArrowDown": @@ -1965,6 +1968,14 @@ class FloatSearchCmdkModal extends SuggestModal { private fileLeaf: WorkspaceLeaf | undefined; private fileEmbeddedView: EmbeddedView | undefined; private searchAbort: AbortController | null = null; + private isComposing = false; + private readonly onCompositionStart = () => { + this.isComposing = true; + this.hidePreview(); + }; + private readonly onCompositionEnd = () => { + this.isComposing = false; + }; constructor(plugin: FloatSearchPlugin) { super(plugin.app); @@ -1989,6 +2000,14 @@ class FloatSearchCmdkModal extends SuggestModal { (this as any).resultContainerEl ); this.bodyEl.appendChild((this as any).resultContainerEl); + this.inputEl.addEventListener( + "compositionstart", + this.onCompositionStart + ); + this.inputEl.addEventListener( + "compositionend", + this.onCompositionEnd + ); } // Required by SuggestModal but unused — we drive the chooser directly @@ -2391,13 +2410,18 @@ class FloatSearchCmdkModal extends SuggestModal { // @ts-ignore onSelectedChange = debounce( (result: CmdkResult, _evt: Event | null) => { + if (this.isComposing) { + this.hidePreview(); + return; + } + if (result?.type === "create" || !result?.file) { this.hidePreview(); } else { this.showPreview(result); } }, - 100 + 200 ); private hidePreview() { @@ -2442,10 +2466,21 @@ class FloatSearchCmdkModal extends SuggestModal { }); } - this.inputEl.focus(); + if (!this.isComposing && document.activeElement !== this.inputEl) { + this.inputEl.focus(); + } } onClose() { + this.inputEl.removeEventListener( + "compositionstart", + this.onCompositionStart + ); + this.inputEl.removeEventListener( + "compositionend", + this.onCompositionEnd + ); + this.isComposing = false; this.fileLeaf?.detach(); this.fileEmbeddedView?.unload(); } diff --git a/src/leafView.ts b/src/leafView.ts index ff099d0..b6a2b83 100644 --- a/src/leafView.ts +++ b/src/leafView.ts @@ -521,7 +521,9 @@ export class EmbeddedView extends nosuper(HoverPopover) { this.opening = false; if (this.detaching) this.hide(); } - this.plugin.app.workspace.setActiveLeaf(leaf); + if (openState?.active !== false) { + this.plugin.app.workspace.setActiveLeaf(leaf); + } return leaf; }