Skip to content

Commit 1c05461

Browse files
committed
Fix truncation of long branch names containing non-ASCII characters
1 parent 7d671d2 commit 1c05461

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

pkg/gui/presentation/branches.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ func getBranchDisplayStrings(
7979
}
8080

8181
// Don't bother shortening branch names that are already 3 characters or less
82-
if len(displayName) > max(availableWidth, 3) {
82+
if runewidth.StringWidth(displayName) > max(availableWidth, 3) {
8383
// Never shorten the branch name to less then 3 characters
8484
len := max(availableWidth, 4)
85-
displayName = displayName[:len-1] + "…"
85+
displayName = runewidth.Truncate(displayName, len, "…")
8686
}
8787
coloredName := nameTextStyle.Sprint(displayName)
8888
if checkedOutByWorkTree {

pkg/gui/presentation/branches_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func Test_getBranchDisplayStrings(t *testing.T) {
5151
useIcons: false,
5252
checkedOutByWorktree: false,
5353
showDivergenceCfg: "none",
54-
expected: []string{"1m", "🍉_special_c…"}, // truncated, but shouldn't
54+
expected: []string{"1m", "🍉_special_char"},
5555
},
5656
{
5757
branch: &models.Branch{Name: "branch_name", Recency: "1m"},
@@ -202,7 +202,7 @@ func Test_getBranchDisplayStrings(t *testing.T) {
202202
useIcons: false,
203203
checkedOutByWorktree: false,
204204
showDivergenceCfg: "none",
205-
expected: []string{"1m", "🍉_special_…"}, // truncated two runes too much
205+
expected: []string{"1m", "🍉_special_ch…"},
206206
},
207207
{
208208
branch: &models.Branch{Name: "branch_name", Recency: "1m"},

0 commit comments

Comments
 (0)