Skip to content

Commit

Permalink
Fix truncation of long branch names containing non-ASCII characters
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhaller committed Jun 22, 2024
1 parent 7d671d2 commit 1c05461
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/gui/presentation/branches.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/gui/presentation/branches_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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"},
Expand Down

0 comments on commit 1c05461

Please sign in to comment.