mirror of
https://github.com/extrawurst/gitui.git
synced 2024-11-27 10:15:07 +03:00
better key handling
This commit is contained in:
parent
7c454629fe
commit
1956e111dd
57
src/app.rs
57
src/app.rs
@ -6,7 +6,7 @@ use crate::{
|
||||
git_utils::{self, Diff},
|
||||
keys, strings,
|
||||
};
|
||||
use crossterm::event::{Event, KeyCode};
|
||||
use crossterm::event::Event;
|
||||
use git2::StatusShow;
|
||||
use itertools::Itertools;
|
||||
use std::{borrow::Cow, path::Path};
|
||||
@ -144,33 +144,32 @@ impl App {
|
||||
return;
|
||||
}
|
||||
|
||||
if ev == Event::Key(KeyCode::Esc.into())
|
||||
|| ev == Event::Key(KeyCode::Char('q').into())
|
||||
{
|
||||
self.do_quit = true;
|
||||
}
|
||||
|
||||
if ev == Event::Key(keys::FOCUS_STATUS) {
|
||||
self.switch_focus(Focus::Status);
|
||||
} else if ev == Event::Key(keys::FOCUS_STAGE) {
|
||||
self.switch_focus(Focus::Stage);
|
||||
} else if ev == Event::Key(keys::FOCUS_RIGHT) {
|
||||
self.switch_focus(Focus::Diff);
|
||||
} else if ev == Event::Key(keys::FOCUS_LEFT) {
|
||||
self.switch_focus(match self.diff_target {
|
||||
DiffTarget::Stage => Focus::Stage,
|
||||
DiffTarget::WorkingDir => Focus::Status,
|
||||
});
|
||||
}
|
||||
|
||||
if let Event::Key(e) = ev {
|
||||
if e.code == KeyCode::Enter {
|
||||
self.index_add_remove();
|
||||
}
|
||||
}
|
||||
|
||||
if ev == Event::Key(KeyCode::Char('D').into()) {
|
||||
self.index_reset();
|
||||
if let Event::Key(k) = ev {
|
||||
match k {
|
||||
keys::EXIT_1 | keys::EXIT_2 => {
|
||||
self.do_quit = true
|
||||
}
|
||||
keys::FOCUS_STATUS => {
|
||||
self.switch_focus(Focus::Status)
|
||||
}
|
||||
keys::FOCUS_STAGE => {
|
||||
self.switch_focus(Focus::Stage)
|
||||
}
|
||||
keys::FOCUS_RIGHT => {
|
||||
self.switch_focus(Focus::Diff)
|
||||
}
|
||||
keys::FOCUS_LEFT => {
|
||||
self.switch_focus(match self.diff_target {
|
||||
DiffTarget::Stage => Focus::Stage,
|
||||
DiffTarget::WorkingDir => Focus::Status,
|
||||
})
|
||||
}
|
||||
keys::STATUS_STAGE_FILE => {
|
||||
self.index_add_remove()
|
||||
}
|
||||
keys::STATUS_RESET_FILE => self.index_reset(),
|
||||
_ => (),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -311,7 +310,7 @@ impl App {
|
||||
}
|
||||
|
||||
fn index_add_remove(&mut self) {
|
||||
if self.index_wd.focused() {
|
||||
if self.diff_target == DiffTarget::WorkingDir {
|
||||
if let Some(i) = self.index_wd.selection() {
|
||||
let path = Path::new(i.path.as_str());
|
||||
|
||||
|
12
src/keys.rs
12
src/keys.rs
@ -7,7 +7,11 @@ const fn no_mod(code: KeyCode) -> KeyEvent {
|
||||
}
|
||||
}
|
||||
|
||||
pub static FOCUS_STATUS: KeyEvent = no_mod(KeyCode::Char('1'));
|
||||
pub static FOCUS_STAGE: KeyEvent = no_mod(KeyCode::Char('2'));
|
||||
pub static FOCUS_RIGHT: KeyEvent = no_mod(KeyCode::Right);
|
||||
pub static FOCUS_LEFT: KeyEvent = no_mod(KeyCode::Left);
|
||||
pub const FOCUS_STATUS: KeyEvent = no_mod(KeyCode::Char('1'));
|
||||
pub const FOCUS_STAGE: KeyEvent = no_mod(KeyCode::Char('2'));
|
||||
pub const FOCUS_RIGHT: KeyEvent = no_mod(KeyCode::Right);
|
||||
pub const FOCUS_LEFT: KeyEvent = no_mod(KeyCode::Left);
|
||||
pub const STATUS_RESET_FILE: KeyEvent = no_mod(KeyCode::Char('D'));
|
||||
pub const STATUS_STAGE_FILE: KeyEvent = no_mod(KeyCode::Enter);
|
||||
pub const EXIT_1: KeyEvent = no_mod(KeyCode::Esc);
|
||||
pub const EXIT_2: KeyEvent = no_mod(KeyCode::Char('q'));
|
||||
|
Loading…
Reference in New Issue
Block a user