From 440244721418ad832d252ad4a1b9aa472a56256e Mon Sep 17 00:00:00 2001 From: Zsolt Viczian Date: Mon, 29 Aug 2022 21:50:54 +0200 Subject: [PATCH] 0.1.11 --- manifest.json | 2 +- src/Scene.ts | 20 ++++++++++++++------ src/Settings.ts | 28 +++++++++++++++++++++++++++- src/lang/locale/en.ts | 4 ++++ src/main.ts | 8 ++++++++ 5 files changed, 54 insertions(+), 8 deletions(-) diff --git a/manifest.json b/manifest.json index fe7f534..2e24158 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "excalibrain", "name": "ExcaliBrain", - "version": "0.1.10", + "version": "0.1.11", "minAppVersion": "0.15.6", "description": "A clean, intuitive and editable graph view for Obsidian", "author": "Zsolt Viczian", diff --git a/src/Scene.ts b/src/Scene.ts index 026d1fb..926c069 100644 --- a/src/Scene.ts +++ b/src/Scene.ts @@ -264,7 +264,7 @@ export class Scene { ea.addElementsToView(); } const frame3 = () => { - api.zoomToFit(null, 5, 0.15); + if(this.plugin.settings.allowAutozoom) api.zoomToFit(null, 5, 0.15); ea.targetView.linksAlwaysOpenInANewPane = true; this.addEventHandler(); this.historyPanel = new HistoryPanel((this.leaf.view as TextFileView).contentEl,this.plugin); @@ -550,19 +550,19 @@ export class Scene { }) ea.getExcalidrawAPI().updateScene({appState: {viewBackgroundColor: this.plugin.settings.backgroundColor}}); - ea.getExcalidrawAPI().zoomToFit(null,5,0.15); + if(this.plugin.settings.allowAutozoom) ea.getExcalidrawAPI().zoomToFit(null,5,0.15); /**REACT 18 ea.targetView.ownerWindow.requestAnimationFrame(()=>{ ea.getExcalidrawAPI().updateScene({appState: {viewBackgroundColor: this.plugin.settings.backgroundColor}}); ea.targetView.ownerWindow.requestAnimationFrame(()=>{ - ea.getExcalidrawAPI().zoomToFit(null,5,0.15); + if(this.plugin.settings.allowAutozoom) ea.getExcalidrawAPI().zoomToFit(null,5,0.15); }); }); */ this.toolsPanel.rerender(); - if(this.focusSearchAfterInitiation) { + if(this.focusSearchAfterInitiation && this.plugin.settings.allowAutofocuOnSearch) { this.toolsPanel.searchElement.focus(); this.focusSearchAfterInitiation = false; } @@ -615,7 +615,7 @@ export class Scene { } if(this.zoomToFitOnNextBrainLeafActivate) { this.zoomToFitOnNextBrainLeafActivate = false; - self.ea.getExcalidrawAPI().zoomToFit(null, 5, 0.15); + if(self.plugin.settings.allowAutozoom) self.ea.getExcalidrawAPI().zoomToFit(null, 5, 0.15); } self.blockUpdateTimer = false; return; @@ -667,8 +667,16 @@ export class Scene { await this.plugin.createIndex(); //temporary + let leafToOpen = leaves[0]; if(leaves.length>0) { - brainEventHandler(leaves[0]); + const lastFilePath = app.workspace.getLastOpenFiles()[0]; + if(lastFilePath && lastFilePath !== "") { + const leaf = leaves.filter(l=>(l.view as FileView)?.file.path === lastFilePath); + if(leaf.length>0) { + leafToOpen = leaf[0]; + } + } + brainEventHandler(leafToOpen); } } diff --git a/src/Settings.ts b/src/Settings.ts index 1fe8f49..70ab7b6 100644 --- a/src/Settings.ts +++ b/src/Settings.ts @@ -64,6 +64,8 @@ export interface ExcaliBrainSettings { ontologySuggesterTrigger: string; ontologySuggesterMidSentenceTrigger: string; boldFields: boolean; + allowAutozoom: boolean; + allowAutofocuOnSearch: boolean; } export const DEFAULT_SETTINGS: ExcaliBrainSettings = { @@ -148,6 +150,8 @@ export const DEFAULT_SETTINGS: ExcaliBrainSettings = { ontologySuggesterTrigger: ":::", ontologySuggesterMidSentenceTrigger: "(", boldFields: false, + allowAutozoom: true, + allowAutofocuOnSearch: true, }; const HIDE_DISABLED_STYLE = "excalibrain-hide-disabled"; @@ -1675,7 +1679,29 @@ export class ExcaliBrainSettingTab extends PluginSettingTab { this.plugin.settings.showNeighborCount = value; this.dirty = true; })) - + + new Setting(containerEl) + .setName(t("ALLOW_AUTOZOOM_NAME")) + .setDesc(fragWithHTML(t("ALLOW_AUTOZOOM_DESC"))) + .addToggle(toggle => + toggle + .setValue(this.plugin.settings.allowAutozoom) + .onChange(value => { + this.plugin.settings.allowAutozoom = value; + this.dirty = true; + })) + + new Setting(containerEl) + .setName(t("ALLOW_AUTOFOCUS_ON_SEARCH_NAME")) + .setDesc(fragWithHTML(t("ALLOW_AUTOFOCUS_ON_SEARCH_DESC"))) + .addToggle(toggle => + toggle + .setValue(this.plugin.settings.allowAutofocuOnSearch) + .onChange(value => { + this.plugin.settings.allowAutofocuOnSearch = value; + this.dirty = true; + })) + containerEl.createEl("h1", { cls: "excalibrain-settings-h1", text: t("STYLE_HEAD") diff --git a/src/lang/locale/en.ts b/src/lang/locale/en.ts index 049abc4..ded9a1d 100644 --- a/src/lang/locale/en.ts +++ b/src/lang/locale/en.ts @@ -89,6 +89,10 @@ export default { "Toggle off: will display the current section of the tag, e.g. assuming the tag above, the graph will display only #reading, #books, #sci-fi respectively as you navigate the tag hierarchy.", SHOW_COUNT_NAME: "Display neighbor count", SHOW_COUNT_DESC: "Show the number of children, parents, friends next to the node gate", + ALLOW_AUTOZOOM_NAME: "Autozoom", + ALLOW_AUTOZOOM_DESC: "Toggle ON: Allow autozoom
Toggle OFF: Disable autozoom", + ALLOW_AUTOFOCUS_ON_SEARCH_NAME: "Autofocus on search", + ALLOW_AUTOFOCUS_ON_SEARCH_DESC: "Toggle ON: Allow autofocus on Search
Toggle OFF: Disable autofocus", TAGLIST_NAME: "Formatted tags", TAGLIST_DESC: "You can specify special formatting rules for Nodes based on tags. If multiple tags are present on the page the first matching a specification " + "will be used.
Tagnames should start with # and may be incomplete. i.e. #book will match #books, #book/fiction, etc.
" + diff --git a/src/main.ts b/src/main.ts index 8d3b854..9fbec62 100644 --- a/src/main.ts +++ b/src/main.ts @@ -500,6 +500,14 @@ export default class ExcaliBrain extends Plugin { return false; } } + if(this.scene?.isCentralLeafStillThere()) { + const f = app.vault.getAbstractFileByPath(path.split("#")[0]); + if(f && f instanceof TFile) { + this.scene.centralLeaf.openFile(f); + this.scene.renderGraphForPath(path); + return false; + } + } //had to add this, because the leaf that opens the file does not get focus, thus the on leaf change //event handler does not run this.scene?.renderGraphForPath(path,false);