forked from kageru/tracc
Add key bindings to go to top or bottom of the list
This commit is contained in:
parent
82df932a99
commit
a7696f34cc
|
@ -12,6 +12,10 @@ pub trait ListView<T: fmt::Display + Clone> {
|
||||||
fn normal_mode(&mut self);
|
fn normal_mode(&mut self);
|
||||||
|
|
||||||
// selection manipulation
|
// selection manipulation
|
||||||
|
fn selection_first(&mut self) {
|
||||||
|
*self.selection_pointer() = 0;
|
||||||
|
}
|
||||||
|
|
||||||
fn selection_up(&mut self) {
|
fn selection_up(&mut self) {
|
||||||
*self.selection_pointer() = self.selection_pointer().saturating_sub(1);
|
*self.selection_pointer() = self.selection_pointer().saturating_sub(1);
|
||||||
}
|
}
|
||||||
|
@ -21,6 +25,10 @@ pub trait ListView<T: fmt::Display + Clone> {
|
||||||
(*self.selection_pointer() + 1).min(self.list().len().saturating_sub(1));
|
(*self.selection_pointer() + 1).min(self.list().len().saturating_sub(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn selection_last(&mut self) {
|
||||||
|
*self.selection_pointer() = self.list().len().saturating_sub(1);
|
||||||
|
}
|
||||||
|
|
||||||
// adding/removing elements
|
// adding/removing elements
|
||||||
fn insert(&mut self, item: T, position: Option<usize>) {
|
fn insert(&mut self, item: T, position: Option<usize>) {
|
||||||
let pos = position.unwrap_or(*self.selection_pointer());
|
let pos = position.unwrap_or(*self.selection_pointer());
|
||||||
|
|
|
@ -51,7 +51,7 @@ impl Tracc {
|
||||||
Focus::Bottom => $action(&mut self.times, $($arg,)*),
|
Focus::Bottom => $action(&mut self.times, $($arg,)*),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
let mut inputs = io::stdin().keys();
|
let mut inputs = io::stdin().keys();
|
||||||
loop {
|
loop {
|
||||||
|
@ -63,6 +63,13 @@ impl Tracc {
|
||||||
Key::Char('q') => break,
|
Key::Char('q') => break,
|
||||||
Key::Char('j') => with_focused!(ListView::selection_down),
|
Key::Char('j') => with_focused!(ListView::selection_down),
|
||||||
Key::Char('k') => with_focused!(ListView::selection_up),
|
Key::Char('k') => with_focused!(ListView::selection_up),
|
||||||
|
Key::Char('G') => with_focused!(ListView::selection_first),
|
||||||
|
// gg
|
||||||
|
Key::Char('g') => {
|
||||||
|
if let Some(Ok(Key::Char('g'))) = inputs.next() {
|
||||||
|
with_focused!(ListView::selection_last);
|
||||||
|
}
|
||||||
|
}
|
||||||
Key::Char('o') => {
|
Key::Char('o') => {
|
||||||
with_focused!(ListView::insert, Default::default(), None);
|
with_focused!(ListView::insert, Default::default(), None);
|
||||||
self.set_mode(Mode::Insert)?;
|
self.set_mode(Mode::Insert)?;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user