Skip to content

Commit 9ee0c06

Browse files
committed
fix: only show non 0 numbers in change status bar
1 parent 60e11b7 commit 9ee0c06

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

src/editor/signs/changesStatusBar.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ export class ChangesStatusBar {
1111
if (plugin.settings.hunks.statusBar === "colored") {
1212
statusBarEl.addClass("git-changes-status-bar-colored");
1313
}
14+
15+
statusBarEl.setAttr("aria-label", "Git diff of the current editor");
16+
this.statusBarEl.setAttribute("data-tooltip-position", "top");
1417
plugin.app.workspace.on("active-leaf-change", (leaf) => {
1518
if (
1619
!leaf ||
@@ -23,41 +26,39 @@ export class ChangesStatusBar {
2326
}
2427

2528
display(hunks: Hunk[], file: TFile | null): void {
26-
if (this.plugin.gitReady) {
27-
const mdView =
28-
this.plugin.app.workspace.getActiveViewOfType(MarkdownView);
29-
if (!mdView || mdView.file?.path !== file?.path) {
30-
return;
31-
}
29+
const mdView =
30+
this.plugin.app.workspace.getActiveViewOfType(MarkdownView);
31+
if (!mdView || mdView.file?.path !== file?.path) {
32+
return;
33+
}
3234

33-
let added: number = 0,
34-
changed: number = 0,
35-
deleted: number = 0;
36-
for (const hunk of hunks) {
37-
added += Math.max(0, hunk.added.count - hunk.removed.count);
38-
changed += Math.min(hunk.added.count, hunk.removed.count);
39-
deleted += Math.max(0, hunk.removed.count - hunk.added.count);
40-
}
41-
// this.statusBarEl.setText(`+${added} ~${changed} -${deleted}`);
42-
this.statusBarEl.empty();
35+
let added: number = 0,
36+
changed: number = 0,
37+
deleted: number = 0;
38+
for (const hunk of hunks) {
39+
added += Math.max(0, hunk.added.count - hunk.removed.count);
40+
changed += Math.min(hunk.added.count, hunk.removed.count);
41+
deleted += Math.max(0, hunk.removed.count - hunk.added.count);
42+
}
43+
this.statusBarEl.empty();
44+
if (added > 0) {
4345
this.statusBarEl.createSpan({
4446
text: `+${added} `,
4547
cls: "git-add",
4648
});
49+
}
50+
if (changed > 0) {
4751
this.statusBarEl.createSpan({
4852
text: `~${changed} `,
4953
cls: "git-change",
5054
});
55+
}
56+
if (deleted > 0) {
5157
this.statusBarEl.createSpan({
5258
text: `-${deleted}`,
5359
cls: "git-delete",
5460
});
55-
} else {
56-
this.statusBarEl.empty();
5761
}
58-
// } else {
59-
// this.statusBarEl.empty();
60-
// }
6162
}
6263

6364
remove() {

src/editor/signs/signsProvider.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { Extension } from "@codemirror/state";
2-
import { Prec } from "@codemirror/state";
32
import type { TFile } from "obsidian";
43
import { eventsPerFilePathSingleton } from "src/editor/eventsPerFilepath";
54
import type ObsidianGit from "src/main";

styles.css

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -673,10 +673,6 @@ div:hover > .git-gutter-marker.git-changedelete {
673673
}
674674
}
675675

676-
/* .git-changes-status-bar > * { */
677-
/* margin-right: 4px; */
678-
/* } */
679-
680676
.git-changes-status-bar-colored {
681677
.git-add {
682678
color: var(--color-green);
@@ -689,6 +685,10 @@ div:hover > .git-gutter-marker.git-changedelete {
689685
}
690686
}
691687

688+
.git-changes-status-bar .git-add {
689+
margin-right: 0.3em;
690+
}
691+
692692
.git-changes-status-bar .git-change {
693-
margin: 0 4px;
693+
margin-right: 0.3em;
694694
}

0 commit comments

Comments
 (0)