From 9f2d6d28841596df4c93ea34739f510c4d8a83eb Mon Sep 17 00:00:00 2001 From: Quorafind Date: Sun, 19 Mar 2023 18:48:06 +0800 Subject: [PATCH] feat: support double tab to focus on file --- src/floatSearchIndex.ts | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/floatSearchIndex.ts b/src/floatSearchIndex.ts index 87fea38..fd79595 100644 --- a/src/floatSearchIndex.ts +++ b/src/floatSearchIndex.ts @@ -276,6 +276,8 @@ class FloatSearchModal extends Modal { private cb: (state: any)=> void; private state: any; + private fileState: any; + private searchCtnEl: HTMLElement; private instructionsEl: HTMLElement; private fileEl: HTMLElement; @@ -561,9 +563,21 @@ class FloatSearchModal extends Modal { active: false, eState: state }); - setTimeout(() => { - (this.searchLeaf.view as SearchView).searchComponent.inputEl.focus(); - }, 0); + + if(this.fileState?.match?.matches[0] === state.match?.matches[0] && state && this.fileState) { + setTimeout(()=>{ + if(this.fileLeaf) { + app.workspace.setActiveLeaf(this.fileLeaf, { + focus: true, + }); + } + }, 0); + } else { + this.fileState = state; + setTimeout(() => { + (this.searchLeaf.view as SearchView).searchComponent.inputEl.focus(); + }, 0); + } return; } @@ -575,11 +589,19 @@ class FloatSearchModal extends Modal { if(e.ctrlKey && e.key === "g") { e.preventDefault(); e.stopPropagation(); - + (this.searchLeaf.view as SearchView).searchComponent.inputEl.focus(); + } + + if(e.key === "Tab" && e.ctrlKey) { + e.preventDefault(); + e.stopPropagation(); + (this.searchLeaf.view as SearchView).searchComponent.inputEl.focus(); } } + + const [createdLeaf, embeddedView] = spawnLeafView(this.plugin, this.fileEl); this.fileLeaf = createdLeaf; this.fileEmbeddedView = embeddedView; @@ -589,6 +611,7 @@ class FloatSearchModal extends Modal { active: false, eState: state }); + this.fileState = state; (this.searchLeaf.view as SearchView).searchComponent.inputEl.focus();