Add vim-like page scrolling

* feat: added match fallback for handle_command SelectViewExt

* feat: HalfPage and FullPage MoveAmount variants

* feat: Display for MoveAmount variants

* feat: fallback for MoveAmount variants in TabView

* feat: ListView FullPage/HalfPage MoveAmount

* feat: default keybinds for page scrolling

* feat: HalfPage/FullPage MoveAmount for HelpView

* feat: removed new defaul keybinds for pagescroll

* style: "upwards" -> "halfpageup" etc.

* feat: toml parse "move pageup" / "move halfpageup"

* chore: cargo fmt

* feat: simplified page scroll command interface

* docs: added `move` to readme

* feat: replace FullPage and HalfPage with Float variant

* fix: remove stray variant

* dosc: update move command

* chore: fmt

* feat: implement MoveAmount::Float for selectview

* chore: fmt
This commit is contained in:
BlakeJC94
2023-03-12 23:26:00 +11:00
committed by GitHub
parent dc2f42fd07
commit 1a0258f197
6 changed files with 53 additions and 4 deletions

View File

@@ -70,6 +70,11 @@ impl ViewExt for HelpView {
MoveAmount::Extreme => {
self.view.scroll_to_top();
}
MoveAmount::Float(scale) => {
let amount = (viewport.height() as f32) * scale;
scroller
.scroll_to_y(viewport.top().saturating_sub(amount as usize));
}
MoveAmount::Integer(amount) => scroller
.scroll_to_y(viewport.top().saturating_sub(*amount as usize)),
};
@@ -80,6 +85,11 @@ impl ViewExt for HelpView {
MoveAmount::Extreme => {
self.view.scroll_to_bottom();
}
MoveAmount::Float(scale) => {
let amount = (viewport.height() as f32) * scale;
scroller
.scroll_to_y(viewport.bottom().saturating_add(amount as usize));
}
MoveAmount::Integer(amount) => scroller
.scroll_to_y(viewport.bottom().saturating_add(*amount as usize)),
};

View File

@@ -542,6 +542,10 @@ impl<I: ListItem + Clone> ViewExt for ListView<I> {
if self.selected > 0 {
match amount {
MoveAmount::Extreme => self.move_focus_to(0),
MoveAmount::Float(scale) => {
let amount = (self.last_size.y as f32) * scale;
self.move_focus(-(amount as i32))
}
MoveAmount::Integer(amount) => self.move_focus(-(*amount)),
}
}
@@ -551,6 +555,10 @@ impl<I: ListItem + Clone> ViewExt for ListView<I> {
if self.selected < last_idx {
match amount {
MoveAmount::Extreme => self.move_focus_to(last_idx),
MoveAmount::Float(scale) => {
let amount = (self.last_size.y as f32) * scale;
self.move_focus(amount as i32)
}
MoveAmount::Integer(amount) => self.move_focus(*amount),
}
}

View File

@@ -144,6 +144,7 @@ impl ViewExt for TabView {
match amount {
MoveAmount::Extreme => self.move_focus_to(0),
MoveAmount::Integer(amount) => self.move_focus(-(*amount)),
_ => (),
}
return Ok(CommandResult::Consumed(None));
}
@@ -151,6 +152,7 @@ impl ViewExt for TabView {
match amount {
MoveAmount::Extreme => self.move_focus_to(last_idx),
MoveAmount::Integer(amount) => self.move_focus(*amount),
_ => (),
}
return Ok(CommandResult::Consumed(None));
}