Truncate description in tab title when it is too long

This commit is contained in:
Antonio Scandurra 2022-07-14 15:12:16 +02:00
parent 07d269234f
commit fd5cb02ea9
3 changed files with 9 additions and 4 deletions

View file

@ -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()