vim hml (#7298)
- Add a setting for `vertical_scroll_offset` - Fix H/M/L in vim with scrolloff Release Notes: - Added a settings for `vertical_scroll_offset` - vim: Fix H/M/L with various values of vertical_scroll_offset --------- Co-authored-by: Vbhavsar <vbhavsar@gmail.com> Co-authored-by: fdionisi <code@fdionisi.me>
This commit is contained in:
parent
e1efa7298e
commit
f09da1a1c8
9 changed files with 57 additions and 28 deletions
|
@ -1044,9 +1044,17 @@ fn window_top(
|
|||
map: &DisplaySnapshot,
|
||||
point: DisplayPoint,
|
||||
text_layout_details: &TextLayoutDetails,
|
||||
times: usize,
|
||||
mut times: usize,
|
||||
) -> (DisplayPoint, SelectionGoal) {
|
||||
let first_visible_line = text_layout_details.anchor.to_display_point(map);
|
||||
let first_visible_line = text_layout_details
|
||||
.scroll_anchor
|
||||
.anchor
|
||||
.to_display_point(map);
|
||||
|
||||
if first_visible_line.row() != 0 && text_layout_details.vertical_scroll_margin as usize > times
|
||||
{
|
||||
times = text_layout_details.vertical_scroll_margin.ceil() as usize;
|
||||
}
|
||||
|
||||
if let Some(visible_rows) = text_layout_details.visible_rows {
|
||||
let bottom_row = first_visible_line.row() + visible_rows as u32;
|
||||
|
@ -1070,7 +1078,10 @@ fn window_middle(
|
|||
text_layout_details: &TextLayoutDetails,
|
||||
) -> (DisplayPoint, SelectionGoal) {
|
||||
if let Some(visible_rows) = text_layout_details.visible_rows {
|
||||
let first_visible_line = text_layout_details.anchor.to_display_point(map);
|
||||
let first_visible_line = text_layout_details
|
||||
.scroll_anchor
|
||||
.anchor
|
||||
.to_display_point(map);
|
||||
let max_rows = (visible_rows as u32).min(map.max_buffer_row());
|
||||
let new_row = first_visible_line.row() + (max_rows.div_euclid(2));
|
||||
let new_col = point.column().min(map.line_len(new_row));
|
||||
|
@ -1085,11 +1096,20 @@ fn window_bottom(
|
|||
map: &DisplaySnapshot,
|
||||
point: DisplayPoint,
|
||||
text_layout_details: &TextLayoutDetails,
|
||||
times: usize,
|
||||
mut times: usize,
|
||||
) -> (DisplayPoint, SelectionGoal) {
|
||||
if let Some(visible_rows) = text_layout_details.visible_rows {
|
||||
let first_visible_line = text_layout_details.anchor.to_display_point(map);
|
||||
let bottom_row = first_visible_line.row() + (visible_rows) as u32;
|
||||
let first_visible_line = text_layout_details
|
||||
.scroll_anchor
|
||||
.anchor
|
||||
.to_display_point(map);
|
||||
let bottom_row = first_visible_line.row()
|
||||
+ (visible_rows + text_layout_details.scroll_anchor.offset.y - 1.).floor() as u32;
|
||||
if bottom_row < map.max_buffer_row()
|
||||
&& text_layout_details.vertical_scroll_margin as usize > times
|
||||
{
|
||||
times = text_layout_details.vertical_scroll_margin.ceil() as usize;
|
||||
}
|
||||
let bottom_row_capped = bottom_row.min(map.max_buffer_row());
|
||||
let new_row = if bottom_row_capped.saturating_sub(times as u32) < first_visible_line.row() {
|
||||
first_visible_line.row()
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
use crate::Vim;
|
||||
use editor::{
|
||||
display_map::ToDisplayPoint,
|
||||
scroll::{ScrollAmount, VERTICAL_SCROLL_MARGIN},
|
||||
DisplayPoint, Editor,
|
||||
display_map::ToDisplayPoint, scroll::ScrollAmount, DisplayPoint, Editor, EditorSettings,
|
||||
};
|
||||
use gpui::{actions, ViewContext};
|
||||
use language::Bias;
|
||||
use settings::Settings;
|
||||
use workspace::Workspace;
|
||||
|
||||
actions!(
|
||||
|
@ -77,6 +76,7 @@ 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, cx, |s| {
|
||||
s.move_with(|map, selection| {
|
||||
|
@ -88,8 +88,8 @@ fn scroll_editor(
|
|||
let new_row = top.row() + selection.head().row() - old_top.row();
|
||||
head = map.clip_point(DisplayPoint::new(new_row, head.column()), Bias::Left)
|
||||
}
|
||||
let min_row = top.row() + VERTICAL_SCROLL_MARGIN as u32;
|
||||
let max_row = top.row() + visible_rows - VERTICAL_SCROLL_MARGIN as u32 - 1;
|
||||
let min_row = top.row() + vertical_scroll_margin as u32;
|
||||
let max_row = top.row() + visible_rows - vertical_scroll_margin as u32 - 1;
|
||||
|
||||
let new_head = if head.row() < min_row {
|
||||
map.clip_point(DisplayPoint::new(min_row, head.column()), Bias::Left)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use editor::{scroll::VERTICAL_SCROLL_MARGIN, test::editor_test_context::ContextHandle};
|
||||
use editor::test::editor_test_context::ContextHandle;
|
||||
use gpui::{px, size, Context};
|
||||
use indoc::indoc;
|
||||
use settings::SettingsStore;
|
||||
|
@ -155,9 +155,7 @@ impl NeovimBackedTestContext {
|
|||
|
||||
pub async fn set_scroll_height(&mut self, rows: u32) {
|
||||
// match Zed's scrolling behavior
|
||||
self.neovim
|
||||
.set_option(&format!("scrolloff={}", VERTICAL_SCROLL_MARGIN))
|
||||
.await;
|
||||
self.neovim.set_option(&format!("scrolloff={}", 3)).await;
|
||||
// +2 to account for the vim command UI at the bottom.
|
||||
self.neovim.set_option(&format!("lines={}", rows + 2)).await;
|
||||
let (line_height, visible_line_count) = self.editor(|editor, cx| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue