Skip to content

Commit

Permalink
Add option to turn off auto-focus
Browse files Browse the repository at this point in the history
  • Loading branch information
kctekn committed Oct 17, 2024
1 parent 80d9025 commit 6ff1ea5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
14 changes: 14 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ interface Settings {
}
openInCurrentTab: boolean;
enableTagsReaction: boolean;
enableAutoFocus: boolean;
enableParagraphLinker: boolean;
snapShotFolder: string;
currentTheme: "dark"|"light";
Expand Down Expand Up @@ -171,6 +172,7 @@ const DEFAULT_SETTINGS: Settings = {
},
openInCurrentTab: false,
enableTagsReaction: true,
enableAutoFocus: true,
enableParagraphLinker: true,
snapShotFolder: "graph-screenshot",
currentTheme: "dark",
Expand Down Expand Up @@ -540,6 +542,18 @@ class TagsroutesSettingsTab extends PluginSettingTab {
.setValue(this.plugin.settings.enableTagsReaction)
}
)
new Setting(containerEl)
.setName('Auto-focus file in explorer')
.setDesc('Automatically navigate and highlight the current file in the file explorer when opened.')
.addToggle((toggle: ToggleComponent) => {
toggle
.onChange(async (value) => {
this.plugin.settings.enableAutoFocus = value;
await this.plugin.saveSettings();
})
.setValue(this.plugin.settings.enableAutoFocus)
}
)
new Setting(containerEl)
.setName('Create paragraph anchor')
.setDesc('Adds an anchor at the end of paragraphs in your notes matching your tag query. This modification enables precise backlinking to specific paragraphs.')
Expand Down
2 changes: 1 addition & 1 deletion src/util/CodeBlockProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ ${result.map(v => "- [[" + v.replace(/.md$/, "") + "]]").join("\n")}
}
//Render it
let executionTimeString
if (globalProgramControl.debugLevel == DebugLevel.INFO) {
if (globalProgramControl.debugLevel == DebugLevel.DEBUG) {
executionTimeString = perf.getTimeCost();
} else {
executionTimeString = `Report refreshed at ${moment(new Date()).format('YYYY-MM-DD HH:mm:ss')} `
Expand Down
44 changes: 30 additions & 14 deletions src/views/TagsRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -934,22 +934,38 @@ export class TagRoutesView extends ItemView {
this.Graph.cameraPosition(newPos, node as any, 3000);
this.highlightOnNodeClick(node)
}
const file = this.app.vault.getAbstractFileByPath(filePath);
if (!file || !(file instanceof TFile)) {
return;
}
// focus on the node in file explorer
const fileExplorerView = this.plugin.app.workspace.getLeavesOfType('file-explorer')[0];
// if (node.type !== 'attachment') {
if (fileExplorerView) {
try {
// 刷新文件浏览器视图
(fileExplorerView.view as any).revealInFolder(file);
} catch (error) {
console.error("Error revealing file in folder:", error);
if (this.plugin.settings.enableAutoFocus) {
const file = this.app.vault.getAbstractFileByPath(filePath);
if (!file || !(file instanceof TFile)) {
return;
}
// 保存当前活动的叶子
const activeLeaf = this.app.workspace.activeLeaf;
// focus on the node in file explorer
const fileExplorerView = this.plugin.app.workspace.getLeavesOfType('file-explorer')[0];
// if (node.type !== 'attachment') {
if (fileExplorerView) {
try {
const fileExplorerEl = fileExplorerView.view.containerEl;
if (fileExplorerEl) {
fileExplorerEl.blur();
// 移除选中状态
const selectedItems = fileExplorerEl.querySelectorAll('.has-focus');
selectedItems.forEach(item => item.classList.remove('has-focus'));
}
// 刷新文件浏览器视图
(fileExplorerView.view as any).revealInFolder(file);
// 将焦点重新设置到之前的活动叶子
if (activeLeaf) {
this.app.workspace.setActiveLeaf(activeLeaf, { focus: true });
(fileExplorerView.view as any).tree.focusedItem = null;
}
} catch (error) {
console.error("Error revealing file in folder:", error);
}
}
}
// }
// }
}
focusGraphTag(tag: string) {
this.focusGraphNodeById(tag);
Expand Down

0 comments on commit 6ff1ea5

Please sign in to comment.