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.

Handle bracketed ellipsis title prefixes (#58269)

Richard Feldman626dc16f02b6
diff --git a/crates/sidebar/src/sidebar.rs b/crates/sidebar/src/sidebar.rs
index 6c4488e31e5..0d94636c985 100644
--- a/crates/sidebar/src/sidebar.rs
+++ b/crates/sidebar/src/sidebar.rs
@@ -274,11 +274,6 @@ fn pick_icon_glyph(prefix: &str) -> Option<SharedString> {
return None;
}
- // Condense a leading run of dots (`...`) into a single ellipsis.
- if prefix.starts_with("..") {
- return Some("\u{2026}".into());
- }
-
// Strip a single pair of surrounding ASCII brackets, e.g. `[!]` -> `!`.
let unwrapped = match prefix.chars().next() {
Some('[') => prefix.strip_prefix('[').and_then(|s| s.strip_suffix(']')),
@@ -292,6 +287,11 @@ fn pick_icon_glyph(prefix: &str) -> Option<SharedString> {
.filter(|s| !s.is_empty())
.unwrap_or(prefix);
+ // Condense a leading run of dots (`...`) into a single ellipsis.
+ if prefix.starts_with("..") {
+ return Some("\u{2026}".into());
+ }
+
// Take the first grapheme cluster so multi-codepoint emoji stay intact.
let first_grapheme = prefix.graphemes(true).next()?;
if first_grapheme.trim().is_empty() {
diff --git a/crates/sidebar/src/sidebar_tests.rs b/crates/sidebar/src/sidebar_tests.rs
index 37b66320732..2991b2d3324 100644
--- a/crates/sidebar/src/sidebar_tests.rs
+++ b/crates/sidebar/src/sidebar_tests.rs
@@ -14771,6 +14771,14 @@ fn test_split_leading_icon_char() {
assert_eq!(icon.as_ref(), "\u{2026}");
assert_eq!(title.as_ref(), "working");
+ let (icon, title, _) = split_leading_icon_char(&"[...] working".into(), &[]).unwrap();
+ assert_eq!(icon.as_ref(), "\u{2026}");
+ assert_eq!(title.as_ref(), "working");
+
+ let (icon, title, _) = split_leading_icon_char(&"[…] working".into(), &[]).unwrap();
+ assert_eq!(icon.as_ref(), "\u{2026}");
+ assert_eq!(title.as_ref(), "working");
+
// Multi-codepoint emoji are kept intact rather than sliced mid-cluster.
let (icon, title, _) = split_leading_icon_char(&"🇺🇸 flag".into(), &[]).unwrap();
assert_eq!(icon.as_ref(), "🇺🇸");