Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
20 changes: 20 additions & 0 deletions pkg/gui/presentation/branches_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ func Test_getBranchDisplayStrings(t *testing.T) {
showDivergenceCfg: "none",
expected: []string{"1m", "branch_name"},
},
{
branch: &models.Branch{Name: "🍉_special_char", Recency: "1m"},
itemOperation: types.ItemOperationNone,
fullDescription: false,
viewWidth: 19,
useIcons: false,
checkedOutByWorktree: false,
showDivergenceCfg: "none",
expected: []string{"1m", "🍉_special_char"},
},
{
branch: &models.Branch{Name: "branch_name", Recency: "1m"},
itemOperation: types.ItemOperationNone,
Expand Down Expand Up @@ -184,6 +194,16 @@ func Test_getBranchDisplayStrings(t *testing.T) {
showDivergenceCfg: "none",
expected: []string{"1m", "branch_na…"},
},
{
branch: &models.Branch{Name: "🍉_special_char", Recency: "1m"},
itemOperation: types.ItemOperationNone,
fullDescription: false,
viewWidth: 18,
useIcons: false,
checkedOutByWorktree: false,
showDivergenceCfg: "none",
expected: []string{"1m", "🍉_special_ch…"},
},
{
branch: &models.Branch{Name: "branch_name", Recency: "1m"},
itemOperation: types.ItemOperationNone,
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/formatting.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ func MaxFn[T any](items []T, fn func(T) int) int {

// TruncateWithEllipsis returns a string, truncated to a certain length, with an ellipsis
func TruncateWithEllipsis(str string, limit int) string {
if runewidth.StringWidth(str) > limit && limit <= 3 {
if runewidth.StringWidth(str) > limit && limit <= 2 {
return strings.Repeat(".", limit)
}
return runewidth.Truncate(str, limit, "...")
return runewidth.Truncate(str, limit, "")
}

func SafeTruncate(str string, limit int) string {
Expand Down
15 changes: 10 additions & 5 deletions pkg/utils/formatting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,22 @@ func TestTruncateWithEllipsis(t *testing.T) {
{
"hello world !",
3,
"...",
"he…",
},
{
"hello world !",
4,
"h...",
"hel…",
},
{
"hello world !",
5,
"he...",
"hell…",
},
{
"hello world !",
12,
"hello wor...",
"hello world…",
},
{
"hello world !",
Expand All @@ -137,13 +137,18 @@ func TestTruncateWithEllipsis(t *testing.T) {
{
"大大大大",
5,
"大...",
"大大…",
},
{
"大大大大",
2,
"..",
},
{
"大大大大",
1,
".",
},
{
"大大大大",
0,
Expand Down