From d406ec06af1f671e3370d120deb439af3cad7fa4 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 22 Jun 2024 13:34:41 +0200 Subject: [PATCH] Fix truncation of long branch names containing non-ASCII characters --- pkg/gui/presentation/branches.go | 4 ++-- pkg/gui/presentation/branches_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/gui/presentation/branches.go b/pkg/gui/presentation/branches.go index aab51fe61..b4c4a75c7 100644 --- a/pkg/gui/presentation/branches.go +++ b/pkg/gui/presentation/branches.go @@ -79,10 +79,10 @@ func getBranchDisplayStrings( } // Don't bother shortening branch names that are already 3 characters or less - if len(displayName) > max(availableWidth, 3) { + if runewidth.StringWidth(displayName) > max(availableWidth, 3) { // Never shorten the branch name to less then 3 characters len := max(availableWidth, 4) - displayName = displayName[:len-1] + "…" + displayName = runewidth.Truncate(displayName, len, "…") } coloredName := nameTextStyle.Sprint(displayName) if checkedOutByWorkTree { diff --git a/pkg/gui/presentation/branches_test.go b/pkg/gui/presentation/branches_test.go index 14012cda2..71dc89c8a 100644 --- a/pkg/gui/presentation/branches_test.go +++ b/pkg/gui/presentation/branches_test.go @@ -51,7 +51,7 @@ func Test_getBranchDisplayStrings(t *testing.T) { useIcons: false, checkedOutByWorktree: false, showDivergenceCfg: "none", - expected: []string{"1m", "πŸ‰_special_c…"}, // truncated, but shouldn't + expected: []string{"1m", "πŸ‰_special_char"}, }, { branch: &models.Branch{Name: "branch_name", Recency: "1m"}, @@ -202,7 +202,7 @@ func Test_getBranchDisplayStrings(t *testing.T) { useIcons: false, checkedOutByWorktree: false, showDivergenceCfg: "none", - expected: []string{"1m", "πŸ‰_special_…"}, // truncated two runes too much + expected: []string{"1m", "πŸ‰_special_ch…"}, }, { branch: &models.Branch{Name: "branch_name", Recency: "1m"},