feat: support double tab to focus on file

This commit is contained in:
Quorafind 2023-03-19 18:48:06 +08:00
parent 3147cb28c7
commit 9f2d6d2884

View file

@ -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();