diff --git a/src/commands.rs b/src/commands.rs index 90a6fa6..6045598 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -379,8 +379,6 @@ impl CommandManager { kb.insert("F3".into(), "playlists".into()); kb.insert("F9".into(), "log".into()); - kb.insert("Up".into(), "move up".into()); - kb.insert("Down".into(), "move down".into()); kb.insert("Left".into(), "move left".into()); kb.insert("Right".into(), "move right".into()); kb.insert("k".into(), "move up".into()); diff --git a/src/playlists.rs b/src/playlists.rs index 58d6212..69c41fc 100644 --- a/src/playlists.rs +++ b/src/playlists.rs @@ -76,7 +76,7 @@ impl Playlists { // force refresh of UI (if visible) self.ev.send(Event::ScreenChange("playlists".to_owned())); - }, + } Err(e) => { error!("can't parse playlist cache: {}", e); } diff --git a/src/ui/listview.rs b/src/ui/listview.rs index 5d4a02e..4a56dec 100644 --- a/src/ui/listview.rs +++ b/src/ui/listview.rs @@ -2,9 +2,10 @@ use std::cmp::{max, min}; use std::sync::{Arc, RwLock}; use cursive::align::HAlign; +use cursive::event::{Event, EventResult, Key}; use cursive::theme::ColorStyle; use cursive::traits::View; -use cursive::{Printer, Vec2}; +use cursive::{Printer, Rect, Vec2}; use unicode_width::UnicodeWidthStr; use queue::Queue; @@ -93,7 +94,37 @@ impl View for ListView { } } + fn on_event(&mut self, e: Event) -> EventResult { + trace!("{:?}", e); + match e { + Event::Key(Key::Up) => { + self.move_focus(-1); + EventResult::Consumed(None) + } + Event::Key(Key::Down) => { + self.move_focus(1); + EventResult::Consumed(None) + } + Event::Key(Key::PageUp) => { + self.move_focus(-10); + EventResult::Consumed(None) + } + Event::Key(Key::PageDown) => { + self.move_focus(10); + EventResult::Consumed(None) + } + _ => EventResult::Ignored, + } + } + fn required_size(&mut self, constraint: Vec2) -> Vec2 { Vec2::new(constraint.x, self.content.read().unwrap().len()) } + + fn important_area(&self, view_size: Vec2) -> Rect { + match self.selected { + Some(index) => Rect::from((view_size.x, index)), + None => Rect::from((0, 0)), + } + } }