Skip to content

Commit f29ba72

Browse files
aiyouxStephan Dilly
authored andcommitted
add bindings q and ESC for exit if no popup visible
1 parent bce652e commit f29ba72

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/app.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ impl App {
261261
log::trace!("event: {:?}", ev);
262262

263263
if let InputEvent::Input(ev) = ev {
264-
if self.check_quit_key(ev) {
264+
if self.check_quit_key(ev) || self.check_weak_quit_key(ev) {
265265
return Ok(());
266266
}
267267

@@ -451,6 +451,18 @@ impl App {
451451
msg
452452
]
453453
);
454+
455+
fn check_weak_quit_key(&mut self, ev: Event) -> bool {
456+
if self.any_popup_visible() { return false }
457+
if let Event::Key(e) = ev {
458+
if e == self.key_config.exit_if_no_popup ||
459+
e == self.key_config.exit_popup {
460+
self.do_quit = true;
461+
return true;
462+
}
463+
}
464+
false
465+
}
454466

455467
fn check_quit_key(&mut self, ev: Event) -> bool {
456468
if let Event::Key(e) = ev {

src/keys.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub struct KeyConfig {
3434
pub focus_above: KeyEvent,
3535
pub focus_below: KeyEvent,
3636
pub exit: KeyEvent,
37+
pub exit_if_no_popup: KeyEvent,
3738
pub exit_popup: KeyEvent,
3839
pub open_commit: KeyEvent,
3940
pub open_commit_editor: KeyEvent,
@@ -101,6 +102,7 @@ impl Default for KeyConfig {
101102
focus_above: KeyEvent { code: KeyCode::Up, modifiers: KeyModifiers::empty()},
102103
focus_below: KeyEvent { code: KeyCode::Down, modifiers: KeyModifiers::empty()},
103104
exit: KeyEvent { code: KeyCode::Char('c'), modifiers: KeyModifiers::CONTROL},
105+
exit_if_no_popup: KeyEvent { code: KeyCode::Char('q'), modifiers: KeyModifiers::empty()},
104106
exit_popup: KeyEvent { code: KeyCode::Esc, modifiers: KeyModifiers::empty()},
105107
open_commit: KeyEvent { code: KeyCode::Char('c'), modifiers: KeyModifiers::empty()},
106108
open_commit_editor: KeyEvent { code: KeyCode::Char('e'), modifiers:KeyModifiers::CONTROL},

0 commit comments

Comments
 (0)