Skip to content

Commit

Permalink
Allow enter to close popup
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasschafer committed Dec 2, 2024
1 parent c54b0dc commit a7651af
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,26 +494,29 @@ impl App {
}

fn handle_key_searching(&mut self, key: &KeyEvent) -> bool {
self.search_fields.show_error_popup = false;
match (key.code, key.modifiers) {
(KeyCode::Enter, _) => {
self.app_event_sender.send(AppEvent::PerformSearch).unwrap();
}
(KeyCode::BackTab, _) | (KeyCode::Tab, KeyModifiers::ALT) => {
self.search_fields.focus_prev();
}
(KeyCode::Tab, _) => {
self.search_fields.focus_next();
}
(code, modifiers) => {
if let FieldName::FixedStrings = self.search_fields.highlighted_field_name() {
// TODO: ideally this should only happen when the field is checked, but for now this will do
self.search_fields.search_mut().clear_error();
};
self.search_fields
.highlighted_field()
.write()
.handle_keys(code, modifiers);
if self.search_fields.show_error_popup {
self.search_fields.show_error_popup = false;
} else {
match (key.code, key.modifiers) {
(KeyCode::Enter, _) => {
self.app_event_sender.send(AppEvent::PerformSearch).unwrap();
}
(KeyCode::BackTab, _) | (KeyCode::Tab, KeyModifiers::ALT) => {
self.search_fields.focus_prev();
}
(KeyCode::Tab, _) => {
self.search_fields.focus_next();
}
(code, modifiers) => {
if let FieldName::FixedStrings = self.search_fields.highlighted_field_name() {
// TODO: ideally this should only happen when the field is checked, but for now this will do
self.search_fields.search_mut().clear_error();
};
self.search_fields
.highlighted_field()
.write()
.handle_keys(code, modifiers);
}
}
};
false
Expand Down Expand Up @@ -568,16 +571,11 @@ impl App {
}

match (key.code, key.modifiers) {
(KeyCode::Esc, _) | (KeyCode::Char('c'), KeyModifiers::CONTROL) => {
let exit = match &self.current_screen {
Screen::SearchFields if self.search_fields.show_error_popup => {
self.search_fields.show_error_popup = false;
false
}
_ => true,
};
(KeyCode::Esc, _) | (KeyCode::Char('c'), KeyModifiers::CONTROL)
if !self.search_fields.show_error_popup =>
{
return Ok(EventHandlingResult {
exit,
exit: true,
rerender: true,
});
}
Expand Down

0 comments on commit a7651af

Please sign in to comment.