mirror of
https://github.com/lostpaul/obsidian-folder-notes.git
synced 2026-07-22 07:40:24 +00:00
Fix #125
This commit is contained in:
parent
f5b7df6a58
commit
1d55c4117c
3 changed files with 45 additions and 4 deletions
|
|
@ -223,10 +223,34 @@ export async function tempDisableSync(plugin: FolderNotesPlugin, folder: TFolder
|
|||
|
||||
export async function openFolderNote(plugin: FolderNotesPlugin, file: TAbstractFile, evt?: MouseEvent) {
|
||||
const path = file.path;
|
||||
if (plugin.app.workspace.getActiveFile()?.path === path && !(Keymap.isModEvent(evt) === 'tab')) { return; }
|
||||
const leaf = plugin.app.workspace.getLeaf(Keymap.isModEvent(evt) || plugin.settings.openInNewTab);
|
||||
if (file instanceof TFile) {
|
||||
await leaf.openFile(file);
|
||||
const focusExistingTab = plugin.settings.focusExistingTab;
|
||||
const activeFilePath = plugin.app.workspace.getActiveFile()?.path;
|
||||
|
||||
// If already active and not opening in new tab, do nothing
|
||||
if (activeFilePath === path && !(Keymap.isModEvent(evt) === 'tab')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Try to find an existing tab with this file open
|
||||
let foundLeaf = null;
|
||||
if (focusExistingTab && file instanceof TFile) {
|
||||
plugin.app.workspace.iterateAllLeaves((leaf) => {
|
||||
if (
|
||||
leaf.getViewState().type === 'markdown' &&
|
||||
(leaf.view as import('obsidian').MarkdownView).file?.path === path
|
||||
) {
|
||||
foundLeaf = leaf;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (foundLeaf) {
|
||||
plugin.app.workspace.setActiveLeaf(foundLeaf, { focus: true });
|
||||
} else {
|
||||
const leaf = plugin.app.workspace.getLeaf(Keymap.isModEvent(evt) || plugin.settings.openInNewTab);
|
||||
if (file instanceof TFile) {
|
||||
await leaf.openFile(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -334,6 +334,21 @@ export async function renderGeneral(settingsTab: SettingsTab) {
|
|||
setting3.infoEl.style.color = settingsTab.app.vault.getConfig('accentColor') as string || '#7d5bed';
|
||||
}
|
||||
|
||||
if (settingsTab.plugin.settings.openInNewTab) {
|
||||
new Setting(containerEl)
|
||||
.setName('Focus existing tab instead of creating a new one')
|
||||
.setDesc('If a folder note is already open in a tab, focus that tab instead of creating a new one.')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.focusExistingTab)
|
||||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.focusExistingTab = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
settingsTab.display();
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Sync folder name')
|
||||
.setDesc('Automatically rename the folder note when the folder name is changed')
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ export interface FolderNotesSettings {
|
|||
underlineFolderInPath: boolean;
|
||||
openFolderNoteOnClickInPath: boolean;
|
||||
openInNewTab: boolean;
|
||||
focusExistingTab: boolean;
|
||||
oldFolderNoteName: string | undefined;
|
||||
folderNoteName: string;
|
||||
newFolderNoteName: string;
|
||||
|
|
@ -95,6 +96,7 @@ export const DEFAULT_SETTINGS: FolderNotesSettings = {
|
|||
underlineFolderInPath: true,
|
||||
openFolderNoteOnClickInPath: true,
|
||||
openInNewTab: false,
|
||||
focusExistingTab: false,
|
||||
oldFolderNoteName: undefined,
|
||||
folderNoteName: '{{folder_name}}',
|
||||
folderNoteType: '.md',
|
||||
|
|
|
|||
Loading…
Reference in a new issue