Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

agent: Truncate display name using grapheme clusters in config option selector (#59898)

DamonXueb6e1e2788771
diff --git a/Cargo.lock b/Cargo.lock
index 6f0590bd0cc..8aeffc53c8f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -546,6 +546,7 @@ dependencies = [
"tree-sitter-md",
"ui",
"ui_input",
+ "unicode-segmentation",
"unindent",
"url",
"util",
diff --git a/crates/agent_ui/Cargo.toml b/crates/agent_ui/Cargo.toml
index bd1ed2b0ff9..8b25804d724 100644
--- a/crates/agent_ui/Cargo.toml
+++ b/crates/agent_ui/Cargo.toml
@@ -108,6 +108,7 @@ theme_settings.workspace = true
time.workspace = true
ui.workspace = true
ui_input.workspace = true
+unicode-segmentation.workspace = true
url.workspace = true
util.workspace = true
uuid.workspace = true
diff --git a/crates/agent_ui/src/config_options.rs b/crates/agent_ui/src/config_options.rs
index 9d34aedede2..405b6c64360 100644
--- a/crates/agent_ui/src/config_options.rs
+++ b/crates/agent_ui/src/config_options.rs
@@ -18,6 +18,7 @@ use ui::{
ElevationIndex, IconButton, KeyBinding, ListItem, ListItemSpacing, PopoverMenuHandle, Tooltip,
prelude::*,
};
+use unicode_segmentation::UnicodeSegmentation;
use util::ResultExt as _;
use zed_actions::agent::ToggleModelSelector;
@@ -364,10 +365,12 @@ impl ConfigOptionSelector {
};
let value_name = self.current_value_name();
- let display_name = if value_name.len() > 33 {
- format!("{}…", &value_name[..32])
+ let mut graphemes = value_name.graphemes(true);
+ let truncated = graphemes.by_ref().take(32).collect::<String>();
+ let display_name = if graphemes.next().is_some() {
+ format!("{truncated}…")
} else {
- value_name
+ truncated
};
Button::new(