Extract list key bindings to util

Also refactors the Rooms event handling code a bit
This commit is contained in:
Joscha 2022-09-25 22:14:12 +02:00
parent 30276fcbbf
commit c16ad024ed
2 changed files with 157 additions and 102 deletions

View file

@ -6,6 +6,7 @@ use toss::terminal::Terminal;
use super::input::{key, InputEvent, KeyBindingsList};
use super::widgets::editor::EditorState;
use super::widgets::list::ListState;
pub fn prompt(
terminal: &mut Terminal,
@ -23,6 +24,35 @@ pub fn prompt(
content
}
//////////
// List //
//////////
pub fn list_list_key_bindings(bindings: &mut KeyBindingsList) {
bindings.binding("j/k, ↓/↑", "move cursor up/down");
bindings.binding("g, home", "move cursor to top");
bindings.binding("G, end", "move cursor to bottom");
bindings.binding("ctrl+y/e", "scroll up/down");
}
pub fn handle_list_input_event<Id: Clone>(list: &mut ListState<Id>, event: &InputEvent) -> bool {
match event {
key!('k') | key!(Up) => list.move_cursor_up(),
key!('j') | key!(Down) => list.move_cursor_down(),
key!('g') | key!(Home) => list.move_cursor_to_top(),
key!('G') | key!(End) => list.move_cursor_to_bottom(),
key!(Ctrl + 'y') => list.scroll_up(1),
key!(Ctrl + 'e') => list.scroll_down(1),
_ => return false,
}
true
}
////////////
// Editor //
////////////
fn list_editor_editing_key_bindings(
bindings: &mut KeyBindingsList,
char_filter: impl Fn(char) -> bool,