feat: configure half-page viewport scroll distance

This commit is contained in:
Valdemar Lorenzen
2026-10-16 10:25:27 +02:00
parent 5a8c37b2f2
commit 284ddd3713
11 changed files with 96 additions and 7 deletions
+12 -2
View File
@@ -13,7 +13,7 @@ use std::collections::{BTreeMap, HashMap, HashSet, VecDeque};
use std::fmt;
use std::fs::{self, OpenOptions};
use std::io::{self, Read, Write};
use std::num::NonZeroU8;
use std::num::{NonZeroU8, NonZeroUsize};
use std::ops::Range;
#[cfg(unix)]
use std::os::unix::fs::{MetadataExt, OpenOptionsExt};
@@ -2009,6 +2009,7 @@ pub struct Editor {
popup: PopupConfig,
labels: BTreeMap<String, String>,
scroll_distance: Option<usize>,
scroll_half_page_lines: Option<NonZeroUsize>,
highlight_trailing_whitespace: bool,
whitespace_characters: BTreeMap<char, char>,
whitespace_scope: WhitespaceScope,
@@ -2119,6 +2120,7 @@ impl Editor {
popup: PopupConfig::default(),
labels: BTreeMap::new(),
scroll_distance: Some(0),
scroll_half_page_lines: None,
highlight_trailing_whitespace: false,
whitespace_characters: BTreeMap::new(),
whitespace_scope: WhitespaceScope::All,
@@ -4116,6 +4118,10 @@ impl Editor {
self.scroll_distance = distance;
}
pub(crate) fn set_scroll_half_page_lines(&mut self, lines: Option<NonZeroUsize>) {
self.scroll_half_page_lines = lines;
}
pub(crate) fn highlight_trailing_whitespace(&self) -> bool {
self.highlight_trailing_whitespace
}
@@ -5829,7 +5835,11 @@ impl Editor {
pub(crate) fn take_viewport_scroll(&self, height: usize) -> isize {
let (rows, halves) = self.active.view.viewport_scroll.take();
rows.saturating_add(halves.saturating_mul((height / 2).max(1) as isize))
let lines = self
.scroll_half_page_lines
.map_or((height / 2).max(1), NonZeroUsize::get);
let lines = isize::try_from(lines).unwrap_or(isize::MAX);
rows.saturating_add(halves.saturating_mul(lines))
}
fn reveal_caret(&mut self) {