- 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:
Conrad Irwin 2024-02-02 19:24:36 -07:00 committed by GitHub
parent e1efa7298e
commit f09da1a1c8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 57 additions and 28 deletions

View file

@ -586,8 +586,9 @@ impl DisplaySnapshot {
text_system,
editor_style,
rem_size,
anchor: _,
scroll_anchor: _,
visible_rows: _,
vertical_scroll_margin: _,
}: &TextLayoutDetails,
) -> Arc<LineLayout> {
let mut runs = Vec::new();

View file

@ -1430,7 +1430,7 @@ impl Editor {
buffer: buffer.clone(),
display_map: display_map.clone(),
selections,
scroll_manager: ScrollManager::new(),
scroll_manager: ScrollManager::new(cx),
columnar_selection_tail: None,
add_selections_state: None,
select_next_state: None,
@ -3086,8 +3086,9 @@ impl Editor {
text_system: cx.text_system().clone(),
editor_style: self.style.clone().unwrap(),
rem_size: cx.rem_size(),
anchor: self.scroll_manager.anchor().anchor,
scroll_anchor: self.scroll_manager.anchor(),
visible_rows: self.visible_line_count(),
vertical_scroll_margin: self.scroll_manager.vertical_scroll_margin,
}
}
@ -8762,6 +8763,8 @@ impl Editor {
)),
cx,
);
self.scroll_manager.vertical_scroll_margin =
EditorSettings::get_global(cx).vertical_scroll_margin;
cx.notify();
}

View file

@ -11,6 +11,7 @@ pub struct EditorSettings {
pub completion_documentation_secondary_query_debounce: u64,
pub use_on_type_format: bool,
pub scrollbar: Scrollbar,
pub vertical_scroll_margin: f32,
pub relative_line_numbers: bool,
pub seed_search_query_from_cursor: SeedQuerySetting,
pub redact_private_values: bool,
@ -87,6 +88,11 @@ pub struct EditorSettingsContent {
pub use_on_type_format: Option<bool>,
/// Scrollbar related settings
pub scrollbar: Option<ScrollbarContent>,
/// The number of lines to keep above/below the cursor when auto-scrolling.
///
/// Default: 3.
pub vertical_scroll_margin: Option<f32>,
/// Whether the line numbers on editors gutter are relative or not.
///
/// Default: false

View file

@ -2,14 +2,12 @@
//! in editor given a given motion (e.g. it handles converting a "move left" command into coordinates in editor). It is exposed mostly for use by vim crate.
use super::{Bias, DisplayPoint, DisplaySnapshot, SelectionGoal, ToDisplayPoint};
use crate::{char_kind, CharKind, EditorStyle, ToOffset, ToPoint};
use crate::{char_kind, scroll::ScrollAnchor, CharKind, EditorStyle, ToOffset, ToPoint};
use gpui::{px, Pixels, WindowTextSystem};
use language::Point;
use std::{ops::Range, sync::Arc};
use multi_buffer::Anchor;
/// Defines search strategy for items in `movement` module.
/// `FindRange::SingeLine` only looks for a match on a single line at a time, whereas
/// `FindRange::MultiLine` keeps going until the end of a string.
@ -25,8 +23,9 @@ pub struct TextLayoutDetails {
pub(crate) text_system: Arc<WindowTextSystem>,
pub(crate) editor_style: EditorStyle,
pub(crate) rem_size: Pixels,
pub anchor: Anchor,
pub scroll_anchor: ScrollAnchor,
pub visible_rows: Option<f32>,
pub vertical_scroll_margin: f32,
}
/// Returns a column to the left of the current point, wrapping

View file

@ -6,13 +6,14 @@ use crate::{
display_map::{DisplaySnapshot, ToDisplayPoint},
hover_popover::hide_hover,
persistence::DB,
Anchor, DisplayPoint, Editor, EditorEvent, EditorMode, InlayHintRefreshReason,
Anchor, DisplayPoint, Editor, EditorEvent, EditorMode, EditorSettings, InlayHintRefreshReason,
MultiBufferSnapshot, ToPoint,
};
pub use autoscroll::{Autoscroll, AutoscrollStrategy};
use gpui::{point, px, AppContext, Entity, Global, Pixels, Task, ViewContext};
use gpui::{point, px, AppContext, Entity, Global, Pixels, Task, ViewContext, WindowContext};
use language::{Bias, Point};
pub use scroll_amount::ScrollAmount;
use settings::Settings;
use std::{
cmp::Ordering,
time::{Duration, Instant},
@ -21,7 +22,6 @@ use util::ResultExt;
use workspace::{ItemId, WorkspaceId};
pub const SCROLL_EVENT_SEPARATION: Duration = Duration::from_millis(28);
pub const VERTICAL_SCROLL_MARGIN: f32 = 3.;
const SCROLLBAR_SHOW_INTERVAL: Duration = Duration::from_secs(1);
#[derive(Default)]
@ -128,7 +128,7 @@ impl OngoingScroll {
}
pub struct ScrollManager {
vertical_scroll_margin: f32,
pub(crate) vertical_scroll_margin: f32,
anchor: ScrollAnchor,
ongoing: OngoingScroll,
autoscroll_request: Option<(Autoscroll, bool)>,
@ -140,9 +140,9 @@ pub struct ScrollManager {
}
impl ScrollManager {
pub fn new() -> Self {
pub fn new(cx: &mut WindowContext) -> Self {
ScrollManager {
vertical_scroll_margin: VERTICAL_SCROLL_MARGIN,
vertical_scroll_margin: EditorSettings::get_global(cx).vertical_scroll_margin,
anchor: ScrollAnchor::new(),
ongoing: OngoingScroll::new(),
autoscroll_request: None,