diff --git a/manifest.json b/manifest.json index c535a81..8f1ca2d 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-dictionary-plugin", "name": "Dictionary", - "version": "2.17.0", + "version": "2.17.1", "minAppVersion": "0.12.11", "description": "This is a simple dictionary for the Obsidian Note-Taking Tool.", "author": "phibr0", diff --git a/src/localDictionaryBuilder.ts b/src/localDictionaryBuilder.ts index 865ec29..ce8f079 100644 --- a/src/localDictionaryBuilder.ts +++ b/src/localDictionaryBuilder.ts @@ -28,7 +28,7 @@ export default class LocalDictionaryBuilder { return string; } - async newNote(content: DictionaryWord): Promise { + async newNote(content: DictionaryWord, openNote = true): Promise { const { plugin, settings } = this; @@ -93,11 +93,13 @@ export default class LocalDictionaryBuilder { await plugin.app.vault.createFolder(normalizePath(`${settings.folder ? settings.folder + '/' : ''}${settings.languageSpecificSubFolders ? langString + '/' : ''}`)); } file = await plugin.app.vault.create(normalizePath(path), contents); - const leaf = plugin.app.workspace.splitActiveLeaf(); - await leaf.openFile(file); - plugin.app.workspace.setActiveLeaf(leaf); + if (openNote) { + const leaf = plugin.app.workspace.splitActiveLeaf(); + await leaf.openFile(file); + plugin.app.workspace.setActiveLeaf(leaf); + } } catch (error) { - new OverwriteModal(this.plugin, normalizePath(path), contents).open(); + new OverwriteModal(this.plugin, normalizePath(path), contents, openNote).open(); } } } @@ -105,11 +107,13 @@ export default class LocalDictionaryBuilder { class OverwriteModal extends Modal { path: string; content: string; + openNote: boolean; - constructor(plugin: DictionaryPlugin, path: string, content: string) { + constructor(plugin: DictionaryPlugin, path: string, content: string, openNote: boolean) { super(plugin.app); this.path = path; this.content = content; + this.openNote = openNote; } onOpen() { @@ -119,14 +123,14 @@ class OverwriteModal extends Modal { this.app.vault.modify(this.app.vault.getAbstractFileByPath(this.path) as TFile, this.content); let oldPaneOpen = false; this.app.workspace.iterateAllLeaves((leaf) => { - if(leaf.view instanceof MarkdownView) { - if((leaf.getViewState().state.file as string).endsWith(this.path)) { + if (leaf.view instanceof MarkdownView) { + if ((leaf.getViewState().state.file as string).endsWith(this.path)) { oldPaneOpen = true; this.app.workspace.setActiveLeaf(leaf); } } }); - if(!oldPaneOpen) { + if (!oldPaneOpen && this.openNote) { const leaf = this.app.workspace.splitActiveLeaf(); await leaf.openFile(this.app.vault.getAbstractFileByPath(this.path) as TFile); this.app.workspace.setActiveLeaf(leaf); diff --git a/src/ui/dictionary/dictionaryView.svelte b/src/ui/dictionary/dictionaryView.svelte index 499b780..bab5d20 100644 --- a/src/ui/dictionary/dictionaryView.svelte +++ b/src/ui/dictionary/dictionaryView.svelte @@ -1,6 +1,6 @@