-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
vim: Add support for moving to first, middle and last visible lines (H
, L
, M
)
#6919
Conversation
H
).H
).
76e491b
to
67dd861
Compare
This change takes a lot of inspiration from `crates/vim/src/normal/scroll.rs`. The editor had to be passed in in order to compute the top row. The change was implemented to match nvim behavior. However, because there is some margin added in zed, moving the cursor to the same line as nvim causes the window to scroll. This is a bit jarring, and unexpected. Because NeovimBackedTestContext requires compatibility with nvim, the current change does not account for the margin. We can easily account for the scroll by adding `VERTICAL_SCROLL_MARGIN` to the top row. Perhaps there should be a lenient nvim compatibility for some tests. Partially fixes zed-industries#4941.
67dd861
to
079584a
Compare
@@ -299,7 +299,7 @@ impl ScrollManager { | |||
} | |||
|
|||
impl Editor { | |||
pub fn vertical_scroll_margin(&mut self) -> usize { | |||
pub fn vertical_scroll_margin(&self) -> usize { |
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.
Ancillary change
6721088
to
672aaf5
Compare
H
).H
).
H
).H
)
After looking at the failing test, I'm having second thoughts about this implementation. The number of places that need to pass in a cloned |
@vbhavsar Thanks for taking a pass at this! If you'd like to pair on getting this over the line, feel free to book a slot here: https://calendly.com/conradirwin/pairing, Otherwise I'm happy if you want to forge ahead, notes below: I agree with you that we shouldn't be cloning the whole editor everywhere. I think we should instead add another field or two to If we track the first visible row (as a DisplayPoint) and the number of visible rows, then we should be able to calculate what we need in the actions for In terms of neovim compatibility, currently Zed mostly assumes you have |
@ConradIrwin Thanks for the great feedback! Per your suggestion, I am trying to add the first visible row as a DisplayPoint to TextLayoutDetails. The issue I'm running into is that I seem to need the ViewContext in order to get the display point (via scroll_manager). But in editor::text_layout_details I only have access to the WindowContext, which is a parent of ViewContext. The best idea I have is to change text_layout_details to accept the ViewContext instead of WindowContext, but that's a pretty drastic change that will touch a lot of code. Do you have better ideas? Here is the change I am attempting to make: pub fn text_layout_details(&self, cx: WindowContext) -> TextLayoutDetails {
let anchor = self.scroll_manager.anchor().anchor;
let display_map = self.display_map.read(&cx);
let display_snapshot = ??;// --> Need mut ViewContext to get a DisplaySnapshot
let first_visible_row = anchor.to_display_point(display_snapshot); // --> need display_snapshot to get display_point from anchor
TextLayoutDetails {
text_system: cx.text_system().clone(),
editor_style: self.style.clone().unwrap(),
rem_size: cx.rem_size(),
first_visible_row: first_visible_row,
visible_rows: self.visible_line_count(),
}
} |
@vbhavsar Two thoughts, though I haven't looked the whole way:
Look forward to pairing tomorrow! |
Keeping it as an anchor is an excellent suggestion. I like that work is done only when it is needed by the action. The minor con with this approach is that the anchor field will need to be public rather than crate-public. I think that's okay, but let me know if you feel differently. |
Back out previous changes that were passing a cloned Editor instance
@ConradIrwin The updated PR supports On a separate note, it's a bit scary that setting an invalid display point causes the whole program to crash. Is that being tracked as a bug? |
H
)H
, L
, M
)
Awesome, thank you! This is a great improvement. I'm going to merge as is, but if you felt like extra credit.. then implementing Crashing on invalid offsets is by design, failing fast finds failures first (or fffff..... which is how it makes you feel :D). |
Fffff is hilariously accurate. Thanks for enlightening me. |
This change implements the vim motion commands to move the cursor to the top, middle and bottom of the visible view. This feature is requested in #4941.
This change takes inspiration from crates/vim/src/normal/scroll.rs.
A note on the behavior of these commands: Because
NeovimBackedTestContext
requires compatibility with nvim, the current implementation causes slightly non-standard behavior: it causes the editor to scroll a few lines. The standard behavior causes no scrolling. It is easy enough to account for the margin by addingVERTICAL_SCROLL_MARGIN
. However, doing so will cause test failures due to the disparity between nvim and zed states. PerhapsNeovimBackedTestContext
should have a switch to be more tolerant for such cases.Release Notes:
H
,M
, andL
) (#4941).