Fix not able to navigate to files in git commit multibuffer (#42558)
Closes #40851 Release Notes: - Fixed: Commit diff multibuffers now open real project files whenever possible, restoring navigation and annotations inside those excerpts. --------- Co-authored-by: Anthony Eid <anthony@zed.dev>
This commit is contained in:
co-authored by
Anthony Eid
parent
b168679c18
commit
85ccd7c98b
@@ -21936,10 +21936,17 @@ impl Editor {
|
||||
};
|
||||
|
||||
for (buffer, (ranges, scroll_offset)) in new_selections_by_buffer {
|
||||
let editor = buffer
|
||||
.read(cx)
|
||||
.file()
|
||||
.is_none()
|
||||
let buffer_read = buffer.read(cx);
|
||||
let (has_file, is_project_file) = if let Some(file) = buffer_read.file() {
|
||||
(true, project::File::from_dyn(Some(file)).is_some())
|
||||
} else {
|
||||
(false, false)
|
||||
};
|
||||
|
||||
// If project file is none workspace.open_project_item will fail to open the excerpt
|
||||
// in a pre existing workspace item if one exists, because Buffer entity_id will be None
|
||||
// so we check if there's a tab match in that case first
|
||||
let editor = (!has_file || !is_project_file)
|
||||
.then(|| {
|
||||
// Handle file-less buffers separately: those are not really the project items, so won't have a project path or entity id,
|
||||
// so `workspace.open_project_item` will never find them, always opening a new editor.
|
||||
@@ -21973,6 +21980,9 @@ impl Editor {
|
||||
});
|
||||
|
||||
editor.update(cx, |editor, cx| {
|
||||
if has_file && !is_project_file {
|
||||
editor.set_read_only(true);
|
||||
}
|
||||
let autoscroll = match scroll_offset {
|
||||
Some(scroll_offset) => Autoscroll::top_relative(scroll_offset as usize),
|
||||
None => Autoscroll::newest(),
|
||||
@@ -21996,10 +22006,11 @@ impl Editor {
|
||||
});
|
||||
}
|
||||
|
||||
// For now, don't allow opening excerpts in buffers that aren't backed by
|
||||
// regular project files.
|
||||
// Allow opening excerpts for buffers that either belong to the current project
|
||||
// or represent synthetic/non-local files (e.g., git blobs). File-less buffers
|
||||
// are also supported so tests and other in-memory views keep working.
|
||||
fn can_open_excerpts_in_file(file: Option<&Arc<dyn language::File>>) -> bool {
|
||||
file.is_none_or(|file| project::File::from_dyn(Some(file)).is_some())
|
||||
file.is_none_or(|file| project::File::from_dyn(Some(file)).is_some() || !file.is_local())
|
||||
}
|
||||
|
||||
fn marked_text_ranges(&self, cx: &App) -> Option<Vec<Range<MultiBufferOffsetUtf16>>> {
|
||||
|
||||
Reference in New Issue
Block a user