From fd5cb02ea9a1eb3c6945a182752e650ba501c2bf Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 14 Jul 2022 15:12:16 +0200 Subject: [PATCH] Truncate description in tab title when it is too long --- crates/editor/src/editor.rs | 1 + crates/editor/src/items.rs | 8 +++++++- crates/search/src/project_search.rs | 4 +--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index b0373c0fcb4d40b4c3e71b34675ea3c6e5fe68a1..72ba6d60af5f22af5ff4368bef8c8d090a36c744 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -35,6 +35,7 @@ use gpui::{ }; use highlight_matching_bracket::refresh_matching_bracket_highlights; use hover_popover::{hide_hover, HoverState}; +pub use items::MAX_TAB_TITLE_LEN; pub use language::{char_kind, CharKind}; use language::{ BracketPair, Buffer, CodeAction, CodeLabel, Completion, Diagnostic, DiagnosticSeverity, diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rs index f703acdfdbba709812baa3a22eca661af021f4ab..8f215076bb57fe8f16e1f6dcaf6cc9fb7870ee23 100644 --- a/crates/editor/src/items.rs +++ b/crates/editor/src/items.rs @@ -23,6 +23,7 @@ use util::TryFutureExt; use workspace::{FollowableItem, Item, ItemHandle, ItemNavHistory, ProjectItem, StatusItemView}; pub const FORMAT_TIMEOUT: Duration = Duration::from_secs(2); +pub const MAX_TAB_TITLE_LEN: usize = 24; impl FollowableItem for Editor { fn from_state_proto( @@ -320,9 +321,14 @@ impl Item for Editor { ) .with_children(detail.and_then(|detail| { let path = path_for_buffer(&self.buffer, detail, false, cx)?; + let description = path.to_string_lossy(); Some( Label::new( - path.to_string_lossy().into(), + if description.len() > MAX_TAB_TITLE_LEN { + description[..MAX_TAB_TITLE_LEN].to_string() + "…" + } else { + description.into() + }, style.description.text.clone(), ) .contained() diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index 5098222ae0f9a0aed5eb1052c276ce48975ffa85..622b84633ce76f5b35e1500979c8557a192f3cba 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -4,7 +4,7 @@ use crate::{ ToggleWholeWord, }; use collections::HashMap; -use editor::{Anchor, Autoscroll, Editor, MultiBuffer, SelectAll}; +use editor::{Anchor, Autoscroll, Editor, MultiBuffer, SelectAll, MAX_TAB_TITLE_LEN}; use gpui::{ actions, elements::*, platform::CursorStyle, Action, AppContext, ElementBox, Entity, ModelContext, ModelHandle, MutableAppContext, RenderContext, Subscription, Task, View, @@ -26,8 +26,6 @@ use workspace::{ actions!(project_search, [Deploy, SearchInNew, ToggleFocus]); -const MAX_TAB_TITLE_LEN: usize = 24; - #[derive(Default)] struct ActiveSearches(HashMap, WeakViewHandle>);