Skip to content

Commit e7f0db2

Browse files
author
Stephan Dilly
committed
simplify ctrl+c handling, its done first so no one can block it
1 parent 63630eb commit e7f0db2

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

src/app.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ impl App {
9393
pub fn event(&mut self, ev: Event) {
9494
trace!("event: {:?}", ev);
9595

96+
if self.check_quit(ev) {
97+
return;
98+
}
99+
96100
let mut flags = NeedsUpdate::empty();
97101

98102
if event_pump(ev, self.components_mut().as_mut_slice()) {
@@ -110,8 +114,6 @@ impl App {
110114
flags.insert(new_flags);
111115
}
112116

113-
self.check_quit(ev);
114-
115117
let new_flags = self.process_queue();
116118
flags.insert(new_flags);
117119

@@ -163,12 +165,14 @@ impl App {
163165
impl App {
164166
accessors!(self, [msg, reset, commit, help, revlog, status_tab]);
165167

166-
fn check_quit(&mut self, ev: Event) {
168+
fn check_quit(&mut self, ev: Event) -> bool {
167169
if let Event::Key(e) = ev {
168170
if let keys::EXIT = e {
169171
self.do_quit = true;
172+
return true;
170173
}
171174
}
175+
false
172176
}
173177

174178
fn toggle_tabs(&mut self) {

src/components/commit.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
strings, ui,
88
};
99
use asyncgit::{sync, CWD};
10-
use crossterm::event::{Event, KeyCode, KeyModifiers};
10+
use crossterm::event::{Event, KeyCode};
1111
use log::error;
1212
use std::borrow::Cow;
1313
use strings::commands;
@@ -76,17 +76,11 @@ impl Component for CommitComponent {
7676
fn event(&mut self, ev: Event) -> bool {
7777
if self.visible {
7878
if let Event::Key(e) = ev {
79-
let has_ctrl =
80-
e.modifiers.contains(KeyModifiers::CONTROL);
8179
match e.code {
8280
KeyCode::Esc => {
8381
self.hide();
8482
}
8583
KeyCode::Char(c) => {
86-
// ignore and early out on ctrl+c
87-
if c == 'c' && has_ctrl {
88-
return false;
89-
}
9084
self.msg.push(c);
9185
}
9286
KeyCode::Enter if self.can_commit() => {

src/components/reset.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
strings, ui,
88
};
99

10-
use crossterm::event::{Event, KeyCode, KeyModifiers};
10+
use crossterm::event::{Event, KeyCode};
1111
use std::borrow::Cow;
1212
use strings::commands;
1313
use tui::{
@@ -74,13 +74,6 @@ impl Component for ResetComponent {
7474
if self.visible {
7575
if let Event::Key(e) = ev {
7676
return match e.code {
77-
KeyCode::Char(c) => {
78-
// ignore and early out on ctrl+c
79-
!(c == 'c'
80-
&& e.modifiers
81-
.contains(KeyModifiers::CONTROL))
82-
}
83-
8477
KeyCode::Esc => {
8578
self.hide();
8679
true

0 commit comments

Comments
 (0)