Disable nav history in vim scrolls (#32656)
Reland of #30345 to fix merge conflicts with the new skip-completions option Fixes #29431 Fixes #17592 Release Notes: - vim: Scrolls are no longer added to the jumplist
This commit is contained in:
parent
0fe35f440d
commit
9166e66519
7 changed files with 208 additions and 119 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::Vim;
|
||||
use editor::{
|
||||
DisplayPoint, Editor, EditorSettings,
|
||||
DisplayPoint, Editor, EditorSettings, SelectionEffects,
|
||||
display_map::{DisplayRow, ToDisplayPoint},
|
||||
scroll::ScrollAmount,
|
||||
};
|
||||
|
@ -101,69 +101,76 @@ fn scroll_editor(
|
|||
let top_anchor = editor.scroll_manager.anchor().anchor;
|
||||
let vertical_scroll_margin = EditorSettings::get_global(cx).vertical_scroll_margin;
|
||||
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
let mut head = selection.head();
|
||||
let top = top_anchor.to_display_point(map);
|
||||
let starting_column = head.column();
|
||||
editor.change_selections(
|
||||
SelectionEffects::no_scroll().nav_history(false),
|
||||
window,
|
||||
cx,
|
||||
|s| {
|
||||
s.move_with(|map, selection| {
|
||||
let mut head = selection.head();
|
||||
let top = top_anchor.to_display_point(map);
|
||||
let starting_column = head.column();
|
||||
|
||||
let vertical_scroll_margin =
|
||||
(vertical_scroll_margin as u32).min(visible_line_count as u32 / 2);
|
||||
let vertical_scroll_margin =
|
||||
(vertical_scroll_margin as u32).min(visible_line_count as u32 / 2);
|
||||
|
||||
if preserve_cursor_position {
|
||||
let old_top = old_top_anchor.to_display_point(map);
|
||||
let new_row = if old_top.row() == top.row() {
|
||||
DisplayRow(
|
||||
head.row()
|
||||
.0
|
||||
.saturating_add_signed(amount.lines(visible_line_count) as i32),
|
||||
)
|
||||
if preserve_cursor_position {
|
||||
let old_top = old_top_anchor.to_display_point(map);
|
||||
let new_row = if old_top.row() == top.row() {
|
||||
DisplayRow(
|
||||
head.row()
|
||||
.0
|
||||
.saturating_add_signed(amount.lines(visible_line_count) as i32),
|
||||
)
|
||||
} else {
|
||||
DisplayRow(top.row().0 + selection.head().row().0 - old_top.row().0)
|
||||
};
|
||||
head = map.clip_point(DisplayPoint::new(new_row, head.column()), Bias::Left)
|
||||
}
|
||||
|
||||
let min_row = if top.row().0 == 0 {
|
||||
DisplayRow(0)
|
||||
} else {
|
||||
DisplayRow(top.row().0 + selection.head().row().0 - old_top.row().0)
|
||||
DisplayRow(top.row().0 + vertical_scroll_margin)
|
||||
};
|
||||
head = map.clip_point(DisplayPoint::new(new_row, head.column()), Bias::Left)
|
||||
}
|
||||
|
||||
let min_row = if top.row().0 == 0 {
|
||||
DisplayRow(0)
|
||||
} else {
|
||||
DisplayRow(top.row().0 + vertical_scroll_margin)
|
||||
};
|
||||
let max_visible_row = top.row().0.saturating_add(
|
||||
(visible_line_count as u32).saturating_sub(1 + vertical_scroll_margin),
|
||||
);
|
||||
// scroll off the end.
|
||||
let max_row = if top.row().0 + visible_line_count as u32 >= map.max_point().row().0
|
||||
{
|
||||
map.max_point().row()
|
||||
} else {
|
||||
DisplayRow(
|
||||
(top.row().0 + visible_line_count as u32)
|
||||
.saturating_sub(1 + vertical_scroll_margin),
|
||||
)
|
||||
};
|
||||
|
||||
let max_visible_row = top.row().0.saturating_add(
|
||||
(visible_line_count as u32).saturating_sub(1 + vertical_scroll_margin),
|
||||
);
|
||||
// scroll off the end.
|
||||
let max_row = if top.row().0 + visible_line_count as u32 >= map.max_point().row().0 {
|
||||
map.max_point().row()
|
||||
} else {
|
||||
DisplayRow(
|
||||
(top.row().0 + visible_line_count as u32)
|
||||
.saturating_sub(1 + vertical_scroll_margin),
|
||||
)
|
||||
};
|
||||
let new_row = if full_page_up {
|
||||
// Special-casing ctrl-b/page-up, which is special-cased by Vim, it seems
|
||||
// to always put the cursor on the last line of the page, even if the cursor
|
||||
// was before that.
|
||||
DisplayRow(max_visible_row)
|
||||
} else if head.row() < min_row {
|
||||
min_row
|
||||
} else if head.row() > max_row {
|
||||
max_row
|
||||
} else {
|
||||
head.row()
|
||||
};
|
||||
let new_head =
|
||||
map.clip_point(DisplayPoint::new(new_row, starting_column), Bias::Left);
|
||||
|
||||
let new_row = if full_page_up {
|
||||
// Special-casing ctrl-b/page-up, which is special-cased by Vim, it seems
|
||||
// to always put the cursor on the last line of the page, even if the cursor
|
||||
// was before that.
|
||||
DisplayRow(max_visible_row)
|
||||
} else if head.row() < min_row {
|
||||
min_row
|
||||
} else if head.row() > max_row {
|
||||
max_row
|
||||
} else {
|
||||
head.row()
|
||||
};
|
||||
let new_head = map.clip_point(DisplayPoint::new(new_row, starting_column), Bias::Left);
|
||||
|
||||
if selection.is_empty() {
|
||||
selection.collapse_to(new_head, selection.goal)
|
||||
} else {
|
||||
selection.set_head(new_head, selection.goal)
|
||||
};
|
||||
})
|
||||
});
|
||||
if selection.is_empty() {
|
||||
selection.collapse_to(new_head, selection.goal)
|
||||
} else {
|
||||
selection.set_head(new_head, selection.goal)
|
||||
};
|
||||
})
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -424,4 +431,20 @@ mod test {
|
|||
cx.shared_state().await.assert_matches();
|
||||
}
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_scroll_jumps(cx: &mut gpui::TestAppContext) {
|
||||
let mut cx = NeovimBackedTestContext::new(cx).await;
|
||||
|
||||
cx.set_scroll_height(20).await;
|
||||
|
||||
let content = "ˇ".to_owned() + &sample_text(52, 2, 'a');
|
||||
cx.set_shared_state(&content).await;
|
||||
|
||||
cx.simulate_shared_keystrokes("shift-g g g").await;
|
||||
cx.simulate_shared_keystrokes("ctrl-d ctrl-d ctrl-o").await;
|
||||
cx.shared_state().await.assert_matches();
|
||||
cx.simulate_shared_keystrokes("ctrl-o").await;
|
||||
cx.shared_state().await.assert_matches();
|
||||
}
|
||||
}
|
||||
|
|
12
crates/vim/test_data/test_scroll_jumps.json
Normal file
12
crates/vim/test_data/test_scroll_jumps.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{"SetOption":{"value":"scrolloff=3"}}
|
||||
{"SetOption":{"value":"lines=22"}}
|
||||
{"Put":{"state":"ˇaa\nbb\ncc\ndd\nee\nff\ngg\nhh\nii\njj\nkk\nll\nmm\nnn\noo\npp\nqq\nrr\nss\ntt\nuu\nvv\nww\nxx\nyy\nzz\n{{\n||\n}}\n~~\n\n\n\n\n\n\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}}
|
||||
{"Key":"shift-g"}
|
||||
{"Key":"g"}
|
||||
{"Key":"g"}
|
||||
{"Key":"ctrl-d"}
|
||||
{"Key":"ctrl-d"}
|
||||
{"Key":"ctrl-o"}
|
||||
{"Get":{"state":"aa\nbb\ncc\ndd\nee\nff\ngg\nhh\nii\njj\nkk\nll\nmm\nnn\noo\npp\nqq\nrr\nss\ntt\nuu\nvv\nww\nxx\nyy\nzz\n{{\n||\n}}\n~~\n\n\n\n\n\n\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nˇ","mode":"Normal"}}
|
||||
{"Key":"ctrl-o"}
|
||||
{"Get":{"state":"ˇaa\nbb\ncc\ndd\nee\nff\ngg\nhh\nii\njj\nkk\nll\nmm\nnn\noo\npp\nqq\nrr\nss\ntt\nuu\nvv\nww\nxx\nyy\nzz\n{{\n||\n}}\n~~\n\n\n\n\n\n\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","mode":"Normal"}}
|
Loading…
Add table
Add a link
Reference in a new issue