|
|
@ -232,15 +232,29 @@ impl Editor {
|
|
|
|
|
|
|
|
|
|
|
|
match action {
|
|
|
|
match action {
|
|
|
|
Action::Replace => {
|
|
|
|
Action::Replace => {
|
|
|
|
let view = view!(self);
|
|
|
|
let (view, doc) = current_ref!(self);
|
|
|
|
let jump = (
|
|
|
|
// If the current view is an empty scratch buffer and is not displayed in any other views, delete it.
|
|
|
|
view.doc,
|
|
|
|
// Boolean value is determined before the call to `view_mut` because the operation requires a borrow
|
|
|
|
self.documents[view.doc].selection(view.id).clone(),
|
|
|
|
// of `self.tree`, which is mutably borrowed when `view_mut` is called.
|
|
|
|
);
|
|
|
|
let remove_empty_scratch = !doc.is_modified()
|
|
|
|
|
|
|
|
// If the buffer has no path and is not modified, it is an empty scratch buffer.
|
|
|
|
|
|
|
|
&& doc.path().is_none()
|
|
|
|
|
|
|
|
// Ensure the buffer is not displayed in any other splits.
|
|
|
|
|
|
|
|
&& !self
|
|
|
|
|
|
|
|
.tree
|
|
|
|
|
|
|
|
.traverse()
|
|
|
|
|
|
|
|
.any(|(_, v)| v.doc == doc.id && v.id != view.id);
|
|
|
|
let view = view_mut!(self);
|
|
|
|
let view = view_mut!(self);
|
|
|
|
view.jumps.push(jump);
|
|
|
|
if remove_empty_scratch {
|
|
|
|
view.last_accessed_doc = Some(view.doc);
|
|
|
|
// Copy `doc.id` into a variable before calling `self.documents.remove`, which requires a mutable
|
|
|
|
|
|
|
|
// borrow, invalidating direct access to `doc.id`.
|
|
|
|
|
|
|
|
let id = doc.id;
|
|
|
|
|
|
|
|
self.documents.remove(id);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
let jump = (view.doc, doc.selection(view.id).clone());
|
|
|
|
|
|
|
|
view.jumps.push(jump);
|
|
|
|
|
|
|
|
view.last_accessed_doc = Some(view.doc);
|
|
|
|
|
|
|
|
}
|
|
|
|
view.doc = id;
|
|
|
|
view.doc = id;
|
|
|
|
view.offset = Position::default();
|
|
|
|
view.offset = Position::default();
|
|
|
|
|
|
|
|
|
|
|
|