1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-05-19 22:33:16 +02:00

Fix truncation of long branch names containing non-ASCII characters

This commit is contained in:
Stefan Haller 2024-06-22 13:34:41 +02:00
parent 7ec784e2a0
commit d406ec06af
2 changed files with 4 additions and 4 deletions

View File

@ -79,10 +79,10 @@ func getBranchDisplayStrings(
} }
// Don't bother shortening branch names that are already 3 characters or less // 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 // Never shorten the branch name to less then 3 characters
len := max(availableWidth, 4) len := max(availableWidth, 4)
displayName = displayName[:len-1] + "…" displayName = runewidth.Truncate(displayName, len, "…")
} }
coloredName := nameTextStyle.Sprint(displayName) coloredName := nameTextStyle.Sprint(displayName)
if checkedOutByWorkTree { if checkedOutByWorkTree {

View File

@ -51,7 +51,7 @@ func Test_getBranchDisplayStrings(t *testing.T) {
useIcons: false, useIcons: false,
checkedOutByWorktree: false, checkedOutByWorktree: false,
showDivergenceCfg: "none", showDivergenceCfg: "none",
expected: []string{"1m", "🍉_special_c…"}, // truncated, but shouldn't expected: []string{"1m", "🍉_special_char"},
}, },
{ {
branch: &models.Branch{Name: "branch_name", Recency: "1m"}, branch: &models.Branch{Name: "branch_name", Recency: "1m"},
@ -202,7 +202,7 @@ func Test_getBranchDisplayStrings(t *testing.T) {
useIcons: false, useIcons: false,
checkedOutByWorktree: false, checkedOutByWorktree: false,
showDivergenceCfg: "none", showDivergenceCfg: "none",
expected: []string{"1m", "🍉_special_…"}, // truncated two runes too much expected: []string{"1m", "🍉_special_ch…"},
}, },
{ {
branch: &models.Branch{Name: "branch_name", Recency: "1m"}, branch: &models.Branch{Name: "branch_name", Recency: "1m"},