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
+50 -1
View File
@@ -3,7 +3,7 @@ use crate::editor::{Context, Effect, Feature};
use crate::plugin::{DocumentEvent, PluginEvent, PluginUpdate, UpdateEffect};
use serde::{Deserialize, Serialize};
use std::io::{self, BufRead, BufReader, Write};
use std::num::NonZeroU8;
use std::num::{NonZeroU8, NonZeroUsize};
use std::path::{Path, PathBuf};
use std::process::{Child, Command, Stdio};
use std::sync::mpsc::{self, Receiver, RecvTimeoutError, SyncSender};
@@ -46,6 +46,7 @@ pub struct Config {
pub popup: PopupConfig,
pub labels: BTreeMap<String, String>,
pub scroll_distance: Option<usize>,
pub scroll_half_page_lines: Option<NonZeroUsize>,
pub highlight_trailing_whitespace: bool,
pub whitespace_characters: BTreeMap<char, char>,
pub whitespace_scope: crate::editor::WhitespaceScope,
@@ -97,6 +98,7 @@ impl Default for Config {
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: crate::editor::WhitespaceScope::All,
@@ -135,6 +137,7 @@ pub fn load_config(path: &Path) -> Result<Config, String> {
popup,
labels,
scroll_distance,
scroll_half_page_lines,
highlight_trailing_whitespace,
whitespace_characters,
whitespace_scope,
@@ -174,6 +177,7 @@ pub fn load_config(path: &Path) -> Result<Config, String> {
config.popup = popup;
config.labels = labels;
config.scroll_distance = scroll_distance;
config.scroll_half_page_lines = scroll_half_page_lines;
config.highlight_trailing_whitespace = highlight_trailing_whitespace;
config.whitespace_characters = whitespace_characters;
config.whitespace_scope = whitespace_scope;
@@ -512,6 +516,7 @@ struct ConfigFrame {
labels: BTreeMap<String, String>,
#[serde(deserialize_with = "scroll_distance")]
scroll_distance: Option<usize>,
scroll_half_page_lines: Option<NonZeroUsize>,
highlight_trailing_whitespace: bool,
#[serde(deserialize_with = "whitespace_characters")]
whitespace_characters: BTreeMap<char, char>,
@@ -1929,6 +1934,50 @@ end
}
}
#[test]
fn config_scroll_half_page_lines_controls_counted_scrolling_and_rejects_invalid_values() {
let fixture = Fixture::new();
for (value, expected) in [
("nil", 30),
("1", 3),
("7", 21),
("18446744073709551615", isize::MAX),
] {
let path = fixture.file(
"config.rb",
&format!("Vamp.configure {{ |config| config.scroll_half_page_lines = {value} }}"),
);
let mut session =
crate::session::EditorSession::open(None, vec![], Some(&path)).unwrap();
session.handle(crate::editor::Input::Char('3'));
session.handle(crate::editor::Input::Ctrl('d'));
assert_eq!(
session.editor().take_viewport_scroll(20),
expected,
"{value}"
);
}
for value in [
"0",
"-1",
"1.5",
"\"3\"",
"true",
"false",
"18446744073709551616",
] {
let path = fixture.file(
"config.rb",
&format!("Vamp.configure {{ |config| config.scroll_half_page_lines = {value} }}"),
);
let error = load_config(&path).unwrap_err();
assert!(
error.contains("scroll_half_page_lines") && error.contains("must be"),
"{value}: {error}"
);
}
}
#[test]
fn config_scroll_distance_accepts_nil_and_counts_and_rejects_invalid_values() {
let fixture = Fixture::new();