Skip to content

Commit 2e5b344

Browse files
author
Stephan Dilly
authored
branchlist was ignoring unicode boundaries on truncating strings (#603)
* branchlist was ignoring unicode boundaries on truncating strings (fixes #602)
1 parent 0a3c3c8 commit 2e5b344

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

Cargo.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ serde = "1.0"
4040
anyhow = "1.0"
4141
unicode-width = "0.1"
4242
textwrap = "0.13"
43+
unicode-truncate = {version="0.2", git="https://github.com/Aetf/unicode-truncate.git"}
4344

4445
[target.'cfg(all(target_family="unix",not(target_os="macos")))'.dependencies]
4546
which = "4.0"

src/components/branchlist.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use tui::{
2525
widgets::{Block, BorderType, Borders, Clear, Paragraph},
2626
Frame,
2727
};
28+
use unicode_truncate::UnicodeTruncateStr;
2829

2930
use crate::ui::Size;
3031
use anyhow::Result;
@@ -334,7 +335,7 @@ impl BranchListComponent {
334335
let mut commit_message =
335336
displaybranch.top_commit_message.clone();
336337
if commit_message.len() > commit_message_length {
337-
commit_message.truncate(
338+
commit_message.unicode_truncate(
338339
commit_message_length
339340
.saturating_sub(THREE_DOTS_LENGTH),
340341
);
@@ -343,7 +344,7 @@ impl BranchListComponent {
343344

344345
let mut branch_name = displaybranch.name.clone();
345346
if branch_name.len() > branch_name_length {
346-
branch_name.truncate(
347+
branch_name.unicode_truncate(
347348
branch_name_length
348349
.saturating_sub(THREE_DOTS_LENGTH),
349350
);

0 commit comments

Comments
 (0)