Scroll key binding list with cursor keys

This commit is contained in:
Joscha 2023-04-29 01:04:52 +02:00
parent 14e17730dc
commit c04f6a8cb4
2 changed files with 28 additions and 5 deletions

View file

@ -252,7 +252,7 @@ impl Ui {
self.key_bindings_visible = false;
return EventHandleResult::Redraw;
}
if util::handle_list_input_event(&mut self.key_bindings_list, &event, keys) {
if key_bindings::handle_input_event(&mut self.key_bindings_list, &mut event, keys) {
return EventHandleResult::Redraw;
}
// ... and does not let anything below the popup receive events

View file

@ -2,14 +2,14 @@
use std::convert::Infallible;
use cove_config::Config;
use cove_input::{KeyBinding, KeyGroup};
use cove_config::{Config, Keys};
use cove_input::{InputEvent, KeyBinding, KeyGroup};
use crossterm::style::Stylize;
use toss::widgets::{Either2, Join2, Padding, Text};
use toss::{Style, Styled, Widget, WidgetExt};
use super::widgets::{ListBuilder, ListState, Popup};
use super::UiError;
use super::{util, UiError};
type Line = Either2<Text, Join2<Padding<Text>, Text>>;
type Builder = ListBuilder<'static, Infallible, Line>;
@ -19,7 +19,7 @@ fn render_empty(builder: &mut Builder) {
}
fn render_title(builder: &mut Builder, title: &str) {
let style = Style::new().bold();
let style = Style::new().bold().magenta();
builder.add_unsel(Text::new(Styled::new(title, style)).first2());
}
@ -85,3 +85,26 @@ pub fn widget<'a>(
Popup::new(list_builder.build(list), "Key bindings")
}
pub fn handle_input_event(
list: &mut ListState<Infallible>,
event: &mut InputEvent<'_>,
keys: &Keys,
) -> bool {
// To make scrolling with the mouse wheel work as expected
if event.matches(&keys.cursor.up) {
list.scroll_up(1);
return true;
}
if event.matches(&keys.cursor.down) {
list.scroll_down(1);
return true;
}
// List movement must come later, or it shadows the cursor movement keys
if util::handle_list_input_event(list, event, keys) {
return true;
}
false
}