From 6914830ce03651b7f9604ba7be81581636a34f5b Mon Sep 17 00:00:00 2001 From: Vinzent Date: Thu, 15 Sep 2022 14:44:24 +0200 Subject: [PATCH] fix: open diff in new leaf close #306 --- .editorconfig | 10 + src/main.ts | 3 +- .../sidebar/components/fileComponent.svelte | 357 +++++++++--------- .../components/pulledFileComponent.svelte | 171 ++++----- .../components/stagedFileComponent.svelte | 327 ++++++++-------- src/utils.ts | 13 + 6 files changed, 458 insertions(+), 423 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..5fd185c8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +# top-most EditorConfig file +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = tab +indent_size = 4 +tab_width = 4 \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index ee46f97c..fd59c6fb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -15,6 +15,7 @@ import DiffView from "./ui/diff/diffView"; import { GeneralModal } from "./ui/modals/generalModal"; import { IgnoreModal } from "./ui/modals/ignoreModal"; import GitView from "./ui/sidebar/sidebarView"; +import { getNewLeaf } from "./utils"; export default class ObsidianGit extends Plugin { gitManager: GitManager; @@ -130,7 +131,7 @@ export default class ObsidianGit extends Plugin { id: 'open-diff-view', name: 'Open diff view', editorCallback: async (editor, view) => { - this.app.workspace.createLeafBySplit(view.leaf).setViewState({ type: DIFF_VIEW_CONFIG.type, state: { staged: false, file: view.file.path } }); + getNewLeaf().setViewState({ type: DIFF_VIEW_CONFIG.type, state: { staged: false, file: view.file.path } }); }, }); diff --git a/src/ui/sidebar/components/fileComponent.svelte b/src/ui/sidebar/components/fileComponent.svelte index f19d9da4..820ddac1 100644 --- a/src/ui/sidebar/components/fileComponent.svelte +++ b/src/ui/sidebar/components/fileComponent.svelte @@ -1,202 +1,211 @@
- - - {change.vault_path.split("/").last().replace(".md", "")} - -
-
- {#if view.app.vault.getAbstractFileByPath(change.vault_path)} -
- {/if} -
-
-
- {change.working_dir} + -
+ {change.vault_path.split("/").last().replace(".md", "")} + +
+
+ {#if view.app.vault.getAbstractFileByPath(change.vault_path)} +
+ {/if} +
+
+
+ {change.working_dir} +
diff --git a/src/ui/sidebar/components/pulledFileComponent.svelte b/src/ui/sidebar/components/pulledFileComponent.svelte index e3eed400..c5119565 100644 --- a/src/ui/sidebar/components/pulledFileComponent.svelte +++ b/src/ui/sidebar/components/pulledFileComponent.svelte @@ -1,100 +1,101 @@
- - - {change.vault_path.split("/").last().replace(".md", "")} - -
- {change.working_dir} -
+ + + {change.vault_path.split("/").last().replace(".md", "")} + +
+ {change.working_dir} +
diff --git a/src/ui/sidebar/components/stagedFileComponent.svelte b/src/ui/sidebar/components/stagedFileComponent.svelte index a89f5927..9dbf86e7 100644 --- a/src/ui/sidebar/components/stagedFileComponent.svelte +++ b/src/ui/sidebar/components/stagedFileComponent.svelte @@ -1,182 +1,183 @@
- - - {formattedPath.split("/").last().replace(".md", "")} - -
-
- {#if view.app.vault.getAbstractFileByPath(formattedPath)} -
- {/if} -
-
- {change.index} -
+ + + {formattedPath.split("/").last().replace(".md", "")} + +
+
+ {#if view.app.vault.getAbstractFileByPath(formattedPath)} +
+ {/if} +
+
+ {change.index} +
diff --git a/src/utils.ts b/src/utils.ts index 765d82ca..fdb85e62 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,3 +1,5 @@ +import { requireApiVersion, WorkspaceLeaf } from "obsidian"; + export const worthWalking = (filepath: string, root: string) => { if (filepath === '.' || root == null || root.length === 0 || root === '.') { return true; @@ -8,3 +10,14 @@ export const worthWalking = (filepath: string, root: string) => { return filepath.startsWith(root); } }; + + +export function getNewLeaf(): WorkspaceLeaf { + let leaf: WorkspaceLeaf; + if (requireApiVersion("0.16.0")) { + leaf = app.workspace.getLeaf("tab"); + } else { + leaf = app.workspace.createLeafInParent(app.workspace.rootSplit, 0); + } + return leaf; +} \ No newline at end of file