Skip to content

Commit b6603dc

Browse files
committed
refactor: truncate branch name once for sidebar and panel
1 parent f189d57 commit b6603dc

2 files changed

Lines changed: 9 additions & 13 deletions

File tree

src/extensions/default/Git/src/Branch.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -516,18 +516,19 @@ define(function (require, exports) {
516516

517517
EventEmitter.emit(Events.REBASE_MERGE_MODE, mergeInfo.rebaseMode, mergeInfo.mergeMode);
518518

519-
var MAX_LEN = 18;
519+
const MAX_LEN = 18;
520520

521521
const tooltip = StringUtils.format(Strings.ON_BRANCH, branchName);
522-
const html = `<i class="fas fa-code-branch"></i> ${
523-
branchName.length > MAX_LEN ? branchName.substring(0, MAX_LEN) + "\u2026" : branchName
524-
}`;
522+
const displayName = branchName.length > MAX_LEN
523+
? branchName.substring(0, MAX_LEN) + "\u2026"
524+
: branchName;
525+
const html = `<i class="fas fa-code-branch"></i> ${displayName}`;
525526
$gitBranchName
526527
.html(html)
527528
.attr("title", tooltip)
528529
.off("click")
529530
.on("click", toggleDropdown);
530-
Panel.setBranchName(branchName, tooltip);
531+
Panel.setBranchName(displayName, tooltip);
531532
$("#git-panel .git-panel-branch")
532533
.addClass("clickable")
533534
.off("click")

src/extensions/default/Git/src/Panel.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -852,17 +852,12 @@ define(function (require, exports) {
852852
}
853853
}
854854

855-
const BRANCH_MAX_LEN = 18;
856-
857-
// called by Branch.refresh() so the panel indicator always mirrors the sidebar one,
858-
// including merge/rebase decorations like "main|MERGING"
855+
// called by Branch.refresh() with the already truncated display name so the panel
856+
// indicator always mirrors the sidebar one, including decorations like "main|MERGING"
859857
function setBranchName(branchName, tooltip) {
860-
const displayName = branchName.length > BRANCH_MAX_LEN
861-
? branchName.substring(0, BRANCH_MAX_LEN) + "\u2026"
862-
: branchName;
863858
const $branch = $gitPanel.find(".git-panel-branch");
864859
$branch.attr("title", tooltip || "");
865-
$branch.find(".git-branch-name").text(displayName);
860+
$branch.find(".git-branch-name").text(branchName);
866861
}
867862

868863
function refreshCommitCounts() {

0 commit comments

Comments
 (0)