diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2024-06-22 13:34:41 +0200 |
---|---|---|
committer | Stefan Haller <stefan@haller-berlin.de> | 2024-06-23 12:25:28 +0200 |
commit | d406ec06af1f671e3370d120deb439af3cad7fa4 (patch) | |
tree | 503b62c83824c49bf3a0c7eb0d1a72919664ca1a | |
parent | 7ec784e2a053b23809cabcad2750db6f2cac1698 (diff) |
Fix truncation of long branch names containing non-ASCII characters
-rw-r--r-- | pkg/gui/presentation/branches.go | 4 | ||||
-rw-r--r-- | 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"}, |