make contextmenu aware of commands
e.g. to process vim-like keybindings for navigation fixes #108, fixes #157, fixes #178, fixes #199, fixes #250
This commit is contained in:
@@ -6,10 +6,11 @@ use cursive::view::ViewWrapper;
|
||||
use cursive::views::{ScrollView, TextView};
|
||||
use cursive::Cursive;
|
||||
|
||||
use crate::command::Command;
|
||||
use crate::command::{Command, MoveAmount, MoveMode};
|
||||
use crate::commands::CommandResult;
|
||||
use crate::config::config_path;
|
||||
use crate::traits::ViewExt;
|
||||
use cursive::view::scroll::Scroller;
|
||||
|
||||
pub struct HelpView {
|
||||
view: ScrollView<TextView>,
|
||||
@@ -50,10 +51,36 @@ impl ViewExt for HelpView {
|
||||
}
|
||||
|
||||
fn on_command(&mut self, _s: &mut Cursive, cmd: &Command) -> Result<CommandResult, String> {
|
||||
if let Command::Help = cmd {
|
||||
Ok(CommandResult::Consumed(None))
|
||||
} else {
|
||||
Ok(CommandResult::Ignored)
|
||||
match cmd {
|
||||
Command::Help => Ok(CommandResult::Consumed(None)),
|
||||
Command::Move(mode, amount) => {
|
||||
let scroller = self.view.get_scroller_mut();
|
||||
let viewport = scroller.content_viewport();
|
||||
match mode {
|
||||
MoveMode::Up => {
|
||||
match amount {
|
||||
MoveAmount::Extreme => {
|
||||
self.view.scroll_to_top();
|
||||
}
|
||||
MoveAmount::Integer(amount) => scroller
|
||||
.scroll_to_y(viewport.top().saturating_sub(*amount as usize)),
|
||||
};
|
||||
Ok(CommandResult::Consumed(None))
|
||||
}
|
||||
MoveMode::Down => {
|
||||
match amount {
|
||||
MoveAmount::Extreme => {
|
||||
self.view.scroll_to_bottom();
|
||||
}
|
||||
MoveAmount::Integer(amount) => scroller
|
||||
.scroll_to_y(viewport.bottom().saturating_add(*amount as usize)),
|
||||
};
|
||||
Ok(CommandResult::Consumed(None))
|
||||
}
|
||||
_ => Ok(CommandResult::Consumed(None)),
|
||||
}
|
||||
}
|
||||
_ => Ok(CommandResult::Ignored),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user