summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2024-06-22 13:34:41 +0200
committerStefan Haller <stefan@haller-berlin.de>2024-06-23 12:25:28 +0200
commitd406ec06af1f671e3370d120deb439af3cad7fa4 (patch)
tree503b62c83824c49bf3a0c7eb0d1a72919664ca1a /pkg
parent7ec784e2a053b23809cabcad2750db6f2cac1698 (diff)
Fix truncation of long branch names containing non-ASCII characters
Diffstat (limited to 'pkg')
-rw-r--r--pkg/gui/presentation/branches.go4
-rw-r--r--pkg/gui/presentation/branches_test.go4
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"},