refactor: name configurable viewport scroll steps accurately

This commit is contained in:
Valdemar Lorenzen
2026-10-16 10:31:36 +02:00
parent 284ddd3713
commit d1048df345
12 changed files with 80 additions and 54 deletions
+24 -10
View File
@@ -46,7 +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 scroll_step_lines: Option<NonZeroUsize>,
pub highlight_trailing_whitespace: bool,
pub whitespace_characters: BTreeMap<char, char>,
pub whitespace_scope: crate::editor::WhitespaceScope,
@@ -98,7 +98,7 @@ impl Default for Config {
popup: PopupConfig::default(),
labels: BTreeMap::new(),
scroll_distance: Some(0),
scroll_half_page_lines: None,
scroll_step_lines: None,
highlight_trailing_whitespace: false,
whitespace_characters: BTreeMap::new(),
whitespace_scope: crate::editor::WhitespaceScope::All,
@@ -137,7 +137,7 @@ pub fn load_config(path: &Path) -> Result<Config, String> {
popup,
labels,
scroll_distance,
scroll_half_page_lines,
scroll_step_lines,
highlight_trailing_whitespace,
whitespace_characters,
whitespace_scope,
@@ -177,7 +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.scroll_step_lines = scroll_step_lines;
config.highlight_trailing_whitespace = highlight_trailing_whitespace;
config.whitespace_characters = whitespace_characters;
config.whitespace_scope = whitespace_scope;
@@ -516,7 +516,7 @@ struct ConfigFrame {
labels: BTreeMap<String, String>,
#[serde(deserialize_with = "scroll_distance")]
scroll_distance: Option<usize>,
scroll_half_page_lines: Option<NonZeroUsize>,
scroll_step_lines: Option<NonZeroUsize>,
highlight_trailing_whitespace: bool,
#[serde(deserialize_with = "whitespace_characters")]
whitespace_characters: BTreeMap<char, char>,
@@ -1935,7 +1935,7 @@ end
}
#[test]
fn config_scroll_half_page_lines_controls_counted_scrolling_and_rejects_invalid_values() {
fn config_scroll_step_lines_controls_counted_scrolling_and_rejects_invalid_values() {
let fixture = Fixture::new();
for (value, expected) in [
("nil", 30),
@@ -1945,17 +1945,31 @@ end
] {
let path = fixture.file(
"config.rb",
&format!("Vamp.configure {{ |config| config.scroll_half_page_lines = {value} }}"),
&format!(
"Vamp.configure do |config|
config.scroll_step_lines = {value}
config.bind \"alt+j\", config.core.scroll_step_down
config.bind \"alt+k\", config.core.scroll_step_up
end"
),
);
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'));
session.handle(crate::editor::Input::Alt('j'));
assert_eq!(
session.editor().take_viewport_scroll(20),
expected,
"{value}"
);
session.handle(crate::editor::Input::Char('3'));
session.handle(crate::editor::Input::Alt('k'));
let up = if expected == isize::MAX {
isize::MIN
} else {
-expected
};
assert_eq!(session.editor().take_viewport_scroll(20), up, "{value}");
}
for value in [
"0",
@@ -1968,11 +1982,11 @@ end
] {
let path = fixture.file(
"config.rb",
&format!("Vamp.configure {{ |config| config.scroll_half_page_lines = {value} }}"),
&format!("Vamp.configure {{ |config| config.scroll_step_lines = {value} }}"),
);
let error = load_config(&path).unwrap_err();
assert!(
error.contains("scroll_half_page_lines") && error.contains("must be"),
error.contains("scroll_step_lines") && error.contains("must be"),
"{value}: {error}"
);
}