-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
If switching away from an empty scratch buffer, remove it #935
Conversation
helix-view/src/editor.rs
Outdated
&& !self | ||
.tree | ||
.traverse() | ||
.any(|(_, view)| view.doc == doc.id && view.id != view!(self).id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about first changing the view.doc
and view.offset
(L263/264)? This way you don't need to check for view.id != view!(self).id
) here and we can extract this traversal into a method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would require using view_mut!
twice: once to set view.doc
and view.offset
, and once after borrowing self.tree
for the check, which I suppose isn't necessarily wrong, but I just don't like it. We could alternatively do this:
self.tree.traverse().filter(|(_, view)| view.doc == doc.id).count() > 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see. We want to at least get rid of the view!
calls inside any
, since that costs as much as a view_mut
but would be called per iteration here. On L235
we already borrow view
so you should be able to reuse that:
- change L235 to
let (view, doc) = current_ref!(self)
- remove L241 (
let doc = doc!(self);
) - change any to
.any(|(_, v)| v.doc == doc.id && v.id != view.id);
helix-view/src/editor.rs
Outdated
&& !self | ||
.tree | ||
.traverse() | ||
.any(|(_, view)| view.doc == doc.id && view.id != view!(self).id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see. We want to at least get rid of the view!
calls inside any
, since that costs as much as a view_mut
but would be called per iteration here. On L235
we already borrow view
so you should be able to reuse that:
- change L235 to
let (view, doc) = current_ref!(self)
- remove L241 (
let doc = doc!(self);
) - change any to
.any(|(_, v)| v.doc == doc.id && v.id != view.id);
helix-view/src/editor.rs
Outdated
@@ -238,9 +238,28 @@ impl Editor { | |||
self.documents[view.doc].selection(view.id).clone(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After the change to current_ref
, this can now be simplified to
self.documents[view.doc].selection(view.id).clone(), | |
doc.selection(view.id).clone(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to also move this jump definition into if !remove_empty_scratch
. That way we're only constructing and cloning the selection if we actually need the jump. To do that we would need to use view_mut!
twice, but that's cheaper than a clone
https://matrix.to/#/!zMuVRxoqjyxyjSEBXc:matrix.org/$UF70A_vWmDH5EawsTQLnyLVp0qIqokNwVI4aRFXdEd4?via=matrix.org&via=tchncs.de&via=nixos.dev
I had to do some stuff to get around borrow errors.