mirror of
https://github.com/quorafind/Obsidian-Float-Search.git
synced 2026-07-22 07:30:25 +00:00
feat: support toggle preview
This commit is contained in:
parent
e75b533c07
commit
f4741d1edd
2 changed files with 21 additions and 4 deletions
|
|
@ -205,6 +205,7 @@ class FloatSearchModal extends Modal {
|
|||
inputEl.focus();
|
||||
inputEl.onkeydown = (e) => {
|
||||
const currentView = this.searchLeaf.view as SearchView;
|
||||
console.log(this.fileLeaf?.view);
|
||||
switch (e.key) {
|
||||
case "ArrowDown":
|
||||
if (e.shiftKey) {
|
||||
|
|
@ -257,6 +258,21 @@ class FloatSearchModal extends Modal {
|
|||
}}) : this.initFileView(file, undefined);
|
||||
}
|
||||
break;
|
||||
case "e":
|
||||
if(e.ctrlKey) {
|
||||
e.preventDefault();
|
||||
if(this.fileLeaf) {
|
||||
const estate = this.fileLeaf.getViewState();
|
||||
estate.state.mode = "preview" === estate.state.mode ? "source" : "preview";
|
||||
this.fileLeaf.setViewState(estate, {
|
||||
focus: !0
|
||||
});
|
||||
setTimeout(()=>{
|
||||
(this.searchLeaf.view as SearchView).searchComponent.inputEl.focus();
|
||||
}, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -273,9 +289,12 @@ class FloatSearchModal extends Modal {
|
|||
let targetElement = e.target as HTMLElement | null;
|
||||
|
||||
if((this.searchCtnEl as Node).contains(targetElement as Node)) {
|
||||
if(((this.searchLeaf.view as SearchView).searchComponent.inputEl as Node).contains(targetElement as Node) || ((this.searchLeaf.view as SearchView).headerDom.navHeaderEl as Node).contains(targetElement as Node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
while (targetElement) {
|
||||
if (targetElement.classList.contains('tree-item')) {
|
||||
console.log(targetElement);
|
||||
break;
|
||||
}
|
||||
targetElement = targetElement.parentElement;
|
||||
|
|
@ -287,7 +306,6 @@ class FloatSearchModal extends Modal {
|
|||
const currentView = this.searchLeaf.view as SearchView;
|
||||
if(file) {
|
||||
const item = currentView.dom.resultDomLookup.get(file);
|
||||
console.log(item);
|
||||
currentView.dom.setFocusedItem(item);
|
||||
this.initFileView(file, undefined);
|
||||
(this.searchLeaf.view as SearchView).searchComponent.inputEl.focus();
|
||||
|
|
@ -298,8 +316,6 @@ class FloatSearchModal extends Modal {
|
|||
return;
|
||||
}
|
||||
|
||||
console.log(e.target);
|
||||
|
||||
const target = e.target as HTMLElement;
|
||||
const classList = target.classList;
|
||||
|
||||
|
|
|
|||
1
src/types/types-obsidian.d.ts
vendored
1
src/types/types-obsidian.d.ts
vendored
|
|
@ -155,6 +155,7 @@ declare module "obsidian" {
|
|||
onKeyShowMoreAfter(e: KeyboardEvent): void;
|
||||
dom: any;
|
||||
searchComponent: SearchComponent;
|
||||
headerDom: any;
|
||||
}
|
||||
|
||||
interface EmptyView extends View {
|
||||
|
|
|
|||
Loading…
Reference in a new issue