Skip to content

Commit

Permalink
fix: minor source control view improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinzent03 committed Mar 20, 2023
1 parent a59d38a commit fd7792c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 48 deletions.
19 changes: 5 additions & 14 deletions src/ui/sidebar/components/fileComponent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { GitManager } from "src/gitManager";
import { FileStatusResult } from "src/types";
import { DiscardModal } from "src/ui/modals/discardModal";
import { getNewLeaf } from "src/utils";
import { getDisplayPath, getNewLeaf } from "src/utils";
import GitView from "../sidebarView";
export let change: FileStatusResult;
Expand All @@ -21,15 +21,8 @@
function hover(event: MouseEvent) {
//Don't show previews of config- or hidden files.
if (
!change.path.startsWith(view.app.vault.configDir) ||
!change.path.startsWith(".")
) {
hoverPreview(
event,
view as any,
change.vault_path.split("/").last()!.replace(".md", "")
);
if (app.vault.getAbstractFileByPath(change.vault_path)) {
hoverPreview(event, view as any, change.vault_path);
}
}
Expand Down Expand Up @@ -87,9 +80,7 @@
<div
class="nav-file-title"
aria-label-position={side}
aria-label={change.vault_path.split("/").last() != change.vault_path
? change.vault_path
: ""}
aria-label={change.vault_path}
on:click|self={showDiff}
on:auxclick|self={showDiff}
>
Expand All @@ -103,7 +94,7 @@
on:auxclick={showDiff}
class="nav-file-title-content"
>
{change.vault_path.split("/").last()?.replace(".md", "")}
{getDisplayPath(change.vault_path)}
</div>
<div class="tools">
<div class="buttons">
Expand Down
19 changes: 5 additions & 14 deletions src/ui/sidebar/components/pulledFileComponent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { TFile } from "obsidian";
import { hoverPreview } from "obsidian-community-lib";
import { FileStatusResult } from "src/types";
import { getNewLeaf } from "src/utils";
import { getDisplayPath, getNewLeaf } from "src/utils";
import GitView from "../sidebarView";
export let change: FileStatusResult;
Expand All @@ -11,15 +11,8 @@
function hover(event: MouseEvent) {
//Don't show previews of config- or hidden files.
if (
!change.path.startsWith(view.app.vault.configDir) ||
!change.path.startsWith(".")
) {
hoverPreview(
event,
view as any,
change.vault_path.split("/").last()!.replace(".md", "")
);
if (app.vault.getAbstractFileByPath(change.vault_path)) {
hoverPreview(event, view as any, change.vault_path);
}
}
Expand All @@ -36,12 +29,10 @@
<div
class="nav-file-title"
aria-label-position={side}
aria-label={change.vault_path.split("/").last() != change.vault_path
? change.vault_path
: ""}
aria-label={change.vault_path}
>
<div class="nav-file-title-content">
{change.vault_path.split("/").last()?.replace(".md", "")}
{getDisplayPath(change.vault_path)}
</div>
<div class="tools">
<span class="type" data-type={change.working_dir}
Expand Down
21 changes: 6 additions & 15 deletions src/ui/sidebar/components/stagedFileComponent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { DIFF_VIEW_CONFIG } from "src/constants";
import { GitManager } from "src/gitManager";
import { FileStatusResult } from "src/types";
import { getNewLeaf } from "src/utils";
import { getDisplayPath, getNewLeaf } from "src/utils";
import GitView from "../sidebarView";
export let change: FileStatusResult;
Expand All @@ -21,15 +21,8 @@
function hover(event: MouseEvent) {
//Don't show previews of config- or hidden files.
if (
!change.path.startsWith(view.app.vault.configDir) ||
!change.path.startsWith(".")
) {
hoverPreview(
event,
view as any,
formattedPath.split("/").last()!.replace(".md", "")
);
if (app.vault.getAbstractFileByPath(change.vault_path)) {
hoverPreview(event, view as any, change.vault_path);
}
}
Expand Down Expand Up @@ -63,21 +56,19 @@
<div
class="nav-file-title"
aria-label-position={side}
aria-label={formattedPath.split("/").last() != formattedPath
? formattedPath
: ""}
aria-label={change.vault_path}
on:click|self={showDiff}
>
<div
on:click={showDiff}
on:auxclick={showDiff}
class="nav-file-title-content"
>
{formattedPath.split("/").last()?.replace(".md", "")}
{getDisplayPath(change.vault_path)}
</div>
<div class="tools">
<div class="buttons">
{#if view.app.vault.getAbstractFileByPath(formattedPath)}
{#if view.app.vault.getAbstractFileByPath(change.vault_path)}
<div
data-icon="go-to-file"
aria-label="Open File"
Expand Down
5 changes: 1 addition & 4 deletions src/ui/sidebar/components/treeComponent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@
<div
class="nav-folder-title"
aria-label-position={side}
aria-label={entity.vaultPath.split("/").last() !=
entity.vaultPath
? entity.vaultPath
: ""}
aria-label={entity.vaultPath}
on:click|self={() => fold(entity)}
>
<div
Expand Down
3 changes: 2 additions & 1 deletion src/ui/sidebar/gitView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
RootTreeItem,
Status,
} from "src/types";
import { getDisplayPath } from "src/utils";
import { onDestroy } from "svelte";
import { slide } from "svelte/transition";
import { DiscardModal } from "../modals/discardModal";
Expand Down Expand Up @@ -112,7 +113,7 @@
return a.vault_path
.split("/")
.last()!
.localeCompare(b.vault_path.split("/").last()!);
.localeCompare(getDisplayPath(b.vault_path));
};
status.changed.sort(sort);
status.staged.sort(sort);
Expand Down
5 changes: 5 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ export function splitRemoteBranch(
const [remote, ...branch] = remoteBranch.split("/");
return [remote, branch.length === 0 ? undefined : branch.join("/")];
}

export function getDisplayPath(path: string): string {
if (path.endsWith("/")) return path;
return path.split("/").last()!.replace(".md", "");
}

0 comments on commit fd7792c

Please sign in to comment.