mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28:21 +00:00
better key handling
This commit is contained in:
parent
7c454629fe
commit
1956e111dd
2 changed files with 36 additions and 33 deletions
57
src/app.rs
57
src/app.rs
|
|
@ -6,7 +6,7 @@ use crate::{
|
||||||
git_utils::{self, Diff},
|
git_utils::{self, Diff},
|
||||||
keys, strings,
|
keys, strings,
|
||||||
};
|
};
|
||||||
use crossterm::event::{Event, KeyCode};
|
use crossterm::event::Event;
|
||||||
use git2::StatusShow;
|
use git2::StatusShow;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use std::{borrow::Cow, path::Path};
|
use std::{borrow::Cow, path::Path};
|
||||||
|
|
@ -144,33 +144,32 @@ impl App {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ev == Event::Key(KeyCode::Esc.into())
|
if let Event::Key(k) = ev {
|
||||||
|| ev == Event::Key(KeyCode::Char('q').into())
|
match k {
|
||||||
{
|
keys::EXIT_1 | keys::EXIT_2 => {
|
||||||
self.do_quit = true;
|
self.do_quit = true
|
||||||
}
|
}
|
||||||
|
keys::FOCUS_STATUS => {
|
||||||
if ev == Event::Key(keys::FOCUS_STATUS) {
|
self.switch_focus(Focus::Status)
|
||||||
self.switch_focus(Focus::Status);
|
}
|
||||||
} else if ev == Event::Key(keys::FOCUS_STAGE) {
|
keys::FOCUS_STAGE => {
|
||||||
self.switch_focus(Focus::Stage);
|
self.switch_focus(Focus::Stage)
|
||||||
} else if ev == Event::Key(keys::FOCUS_RIGHT) {
|
}
|
||||||
self.switch_focus(Focus::Diff);
|
keys::FOCUS_RIGHT => {
|
||||||
} else if ev == Event::Key(keys::FOCUS_LEFT) {
|
self.switch_focus(Focus::Diff)
|
||||||
self.switch_focus(match self.diff_target {
|
}
|
||||||
DiffTarget::Stage => Focus::Stage,
|
keys::FOCUS_LEFT => {
|
||||||
DiffTarget::WorkingDir => Focus::Status,
|
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 {
|
keys::STATUS_STAGE_FILE => {
|
||||||
self.index_add_remove();
|
self.index_add_remove()
|
||||||
}
|
}
|
||||||
}
|
keys::STATUS_RESET_FILE => self.index_reset(),
|
||||||
|
_ => (),
|
||||||
if ev == Event::Key(KeyCode::Char('D').into()) {
|
};
|
||||||
self.index_reset();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -311,7 +310,7 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn index_add_remove(&mut self) {
|
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() {
|
if let Some(i) = self.index_wd.selection() {
|
||||||
let path = Path::new(i.path.as_str());
|
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 const FOCUS_STATUS: KeyEvent = no_mod(KeyCode::Char('1'));
|
||||||
pub static FOCUS_STAGE: KeyEvent = no_mod(KeyCode::Char('2'));
|
pub const FOCUS_STAGE: KeyEvent = no_mod(KeyCode::Char('2'));
|
||||||
pub static FOCUS_RIGHT: KeyEvent = no_mod(KeyCode::Right);
|
pub const FOCUS_RIGHT: KeyEvent = no_mod(KeyCode::Right);
|
||||||
pub static FOCUS_LEFT: KeyEvent = no_mod(KeyCode::Left);
|
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 a new issue