mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-03 17:44:30 +00:00
fixed a bug where files outside of the project would show 'untitled' in the search bar
This commit is contained in:
parent
b6bb2985f5
commit
19c98bb5ad
3 changed files with 24 additions and 15 deletions
|
@ -1379,10 +1379,11 @@ impl EditorElement {
|
|||
let font_size =
|
||||
(style.text_scale_factor * self.style.text.font_size).round();
|
||||
|
||||
let path = buffer.resolve_file_path(cx, true);
|
||||
let mut filename = None;
|
||||
let mut parent_path = None;
|
||||
if let Some(file) = buffer.file() {
|
||||
let path = file.path();
|
||||
// Can't use .and_then() because `.file_name()` and `.parent()` return references :(
|
||||
if let Some(path) = path {
|
||||
filename = path.file_name().map(|f| f.to_string_lossy().to_string());
|
||||
parent_path =
|
||||
path.parent().map(|p| p.to_string_lossy().to_string() + "/");
|
||||
|
|
|
@ -531,21 +531,17 @@ impl Item for Editor {
|
|||
let buffer = multibuffer.buffer(buffer_id)?;
|
||||
|
||||
let buffer = buffer.read(cx);
|
||||
let filename = if let Some(file) = buffer.file() {
|
||||
if file.path().file_name().is_none()
|
||||
|| self
|
||||
.project
|
||||
let filename = buffer
|
||||
.snapshot()
|
||||
.resolve_file_path(
|
||||
cx,
|
||||
self.project
|
||||
.as_ref()
|
||||
.map(|project| project.read(cx).visible_worktrees(cx).count() > 1)
|
||||
.unwrap_or_default()
|
||||
{
|
||||
file.full_path(cx).to_string_lossy().to_string()
|
||||
} else {
|
||||
file.path().to_string_lossy().to_string()
|
||||
}
|
||||
} else {
|
||||
"untitled".to_string()
|
||||
};
|
||||
.unwrap_or_default(),
|
||||
)
|
||||
.map(|path| path.to_string_lossy().to_string())
|
||||
.unwrap_or_else(|| "untitled".to_string());
|
||||
|
||||
let mut breadcrumbs = vec![Label::new(filename, theme.breadcrumbs.text.clone()).boxed()];
|
||||
breadcrumbs.extend(symbols.into_iter().map(|symbol| {
|
||||
|
|
|
@ -2315,6 +2315,18 @@ impl BufferSnapshot {
|
|||
self.file.as_deref()
|
||||
}
|
||||
|
||||
pub fn resolve_file_path(&self, cx: &AppContext, include_root: bool) -> Option<PathBuf> {
|
||||
if let Some(file) = self.file() {
|
||||
if file.path().file_name().is_none() || include_root {
|
||||
Some(file.full_path(cx))
|
||||
} else {
|
||||
Some(file.path().to_path_buf())
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn file_update_count(&self) -> usize {
|
||||
self.file_update_count
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue