From 9a944ca181efca65feda8416c196ee130d76962c Mon Sep 17 00:00:00 2001 From: artanis Date: Wed, 3 Jun 2026 09:19:28 +0800 Subject: [PATCH] fix: block search during IME composition to prevent premature queries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - FloatSearchModal.initInput: skip keyboard navigation during IME composition (check e.isComposing, e.key === 'Process', e.keyCode === 229) - FloatSearchCmdkModal: set isComposing flag on compositionstart, clear it and trigger updateSuggestions on compositionend - FloatSearchCmdkModal.updateSuggestions: bail out early if isComposing Fixes the bug where typing Chinese pinyin (e.g. 'ka'pai' for '卡牌') triggers search on every keystroke instead of waiting for the composed character to be committed. --- src/floatSearchIndex.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/floatSearchIndex.ts b/src/floatSearchIndex.ts index 6a10cd2..d3a5e9c 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": @@ -1961,6 +1964,7 @@ interface CmdkResult { class FloatSearchCmdkModal extends SuggestModal { plugin: FloatSearchPlugin; private bodyEl: HTMLElement; + private isComposing = false; private previewEl: HTMLElement | undefined; private fileLeaf: WorkspaceLeaf | undefined; private fileEmbeddedView: EmbeddedView | undefined; @@ -1983,6 +1987,14 @@ class FloatSearchCmdkModal extends SuggestModal { onOpen() { super.onOpen(); + this.isComposing = false; + this.inputEl.addEventListener("compositionstart", () => { + this.isComposing = true; + }); + this.inputEl.addEventListener("compositionend", () => { + this.isComposing = false; + this.updateSuggestions(); + }); this.bodyEl = createDiv("float-search-cmdk-body"); this.modalEl.insertBefore( this.bodyEl, @@ -1998,6 +2010,7 @@ class FloatSearchCmdkModal extends SuggestModal { // Override to use progressive rendering via chooser.addSuggestion updateSuggestions() { + if (this.isComposing) return; // Cancel previous in-flight search this.searchAbort?.abort(); const abort = (this.searchAbort = new AbortController());