Differentiate among tabs with the same name

This commit introduces a new, optional `Item::tab_description` method
that lets implementers define a description for the tab with a certain
`detail`. When two or more tabs match the same description, we will
increase the `detail` until tabs don't match anymore or increasing the
`detail` doesn't disambiguate tabs any further.

As soon as we find a valid `detail` that disambiguates tabs enough, we
will pass it to `Item::tab_content`. In `Editor`, this is implemented by
showing more and more of the path's suffix as `detail` is increased.
This commit is contained in:
Antonio Scandurra 2022-07-14 11:49:10 +02:00
parent 4a5b8fd2e6
commit 07d269234f
12 changed files with 171 additions and 25 deletions

View file

@ -14,6 +14,7 @@ use language::{
use settings::Settings;
use smallvec::SmallVec;
use std::{
borrow::Cow,
cell::{Ref, RefCell},
cmp, fmt, io,
iter::{self, FromIterator},
@ -1194,14 +1195,14 @@ impl MultiBuffer {
.collect()
}
pub fn title(&self, cx: &AppContext) -> String {
if let Some(title) = self.title.clone() {
return title;
pub fn title<'a>(&'a self, cx: &'a AppContext) -> Cow<'a, str> {
if let Some(title) = self.title.as_ref() {
return title.into();
}
if let Some(buffer) = self.as_singleton() {
if let Some(file) = buffer.read(cx).file() {
return file.file_name(cx).to_string_lossy().into();
return file.file_name(cx).to_string_lossy();
}
}