Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key binding reword to avoid key not getting registered properly #7

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/app/app_states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl App<'_> {
let local_selected_request = self.get_selected_request_as_local();
let selected_request = local_selected_request.read().unwrap();

let mut base_keys = String::from("Esc ^Enter ^TAB (h)elp (u) (m) ^(a) ^(b) (s) (c)");
let mut base_keys = String::from("Esc Space TAB (h)elp (u) (m) ^(a) ^(b) (s) (c) (v)");

if !self.environments.is_empty() {
base_keys += " (e)";
Expand Down Expand Up @@ -273,7 +273,7 @@ impl App<'_> {
let local_selected_request = self.get_selected_request_as_local();
let selected_request = local_selected_request.read().unwrap();

let mut base_keys = String::from("Esc ^Enter ^TAB (u)rl (m)ethod ^(a)uth ^(b)ody (s)ettings (c)ookies");
let mut base_keys = String::from("Esc Space or ^Enter TAB (u)rl (m)ethod ^(a)uth ^(b)ody (s)ettings (c)ookies (v)iew");

if !self.environments.is_empty() {
base_keys += " (e)nv";
Expand Down
39 changes: 19 additions & 20 deletions src/app/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@ impl App<'_> {
pub async fn handle_events(&mut self) {
// Refreshes the app every tick_rate
if event::poll(self.tick_rate).unwrap() {
// Default state
self.display_full_help = false;

// Block while a key is pressed
if let Event::Key(key) = event::read().unwrap() {
let mut miss_input = false;

let previous_app_state = self.state;
let control_pressed: bool = key.modifiers == KeyModifiers::CONTROL;
let shift_pressed: bool = key.modifiers == KeyModifiers::SHIFT;

// Debug tool
//println!("{:?} {:?}", key.modifiers, key.code);
Expand Down Expand Up @@ -49,7 +45,7 @@ impl App<'_> {
KeyCode::Char('d') => self.delete_element(),
KeyCode::Char('r') => self.rename_element(),

KeyCode::Char('h') => self.display_full_help = true,
KeyCode::Char('h') => self.display_full_help = !self.display_full_help,

_ => miss_input = true
},
Expand Down Expand Up @@ -191,9 +187,9 @@ impl App<'_> {
RequestParamsTabs::QueryParams => match key.code {
KeyCode::Enter if !control_pressed && self.query_params_table.is_selected() => self.edit_request_param_state(),

KeyCode::Up => self.query_params_table.up(),
KeyCode::Down => self.query_params_table.down(),
KeyCode::Left | KeyCode::Right => self.query_params_table.change_y(),
KeyCode::Up if !control_pressed => self.query_params_table.up(),
KeyCode::Down if !control_pressed => self.query_params_table.down(),
KeyCode::Left | KeyCode::Right if !control_pressed => self.query_params_table.change_y(),

KeyCode::Char('n') => self.create_new_query_param(),
KeyCode::Char('d') => self.delete_query_param(),
Expand All @@ -204,17 +200,17 @@ impl App<'_> {
RequestParamsTabs::Auth if self.auth_text_input_selection.usable => match key.code {
KeyCode::Enter if !control_pressed => self.select_request_auth_input_text(),

KeyCode::Up => self.auth_text_input_selection.previous(),
KeyCode::Down => self.auth_text_input_selection.next(),
KeyCode::Up if !control_pressed => self.auth_text_input_selection.previous(),
KeyCode::Down if !control_pressed => self.auth_text_input_selection.next(),

_ => {}
}
RequestParamsTabs::Headers => match key.code {
KeyCode::Enter if !control_pressed && self.headers_table.is_selected() => self.edit_request_header_state(),

KeyCode::Up => self.headers_table.up(),
KeyCode::Down => self.headers_table.down(),
KeyCode::Left | KeyCode::Right => self.headers_table.change_y(),
KeyCode::Up if !control_pressed => self.headers_table.up(),
KeyCode::Down if !control_pressed => self.headers_table.down(),
KeyCode::Left | KeyCode::Right if !control_pressed => self.headers_table.change_y(),

KeyCode::Char('n') => self.create_new_header(),
KeyCode::Char('d') => self.delete_header(),
Expand All @@ -226,9 +222,9 @@ impl App<'_> {
KeyCode::Enter if !control_pressed && self.body_form_table.is_selected() => self.edit_request_body_table_state(),
KeyCode::Enter if !control_pressed => self.edit_request_body_string_state(),

KeyCode::Up => self.body_form_table.up(),
KeyCode::Down => self.body_form_table.down(),
KeyCode::Left | KeyCode::Right => self.body_form_table.change_y(),
KeyCode::Up if !control_pressed => self.body_form_table.up(),
KeyCode::Down if !control_pressed => self.body_form_table.down(),
KeyCode::Left | KeyCode::Right if !control_pressed=> self.body_form_table.change_y(),

KeyCode::Char('n') => self.create_new_form_data(),
KeyCode::Char('d') => self.delete_form_data(),
Expand All @@ -245,7 +241,7 @@ impl App<'_> {
KeyCode::Char('c') => self.display_cookies_state(),
KeyCode::Char('e') => self.next_environment(),

KeyCode::Char('h') => self.display_full_help = true,
KeyCode::Char('h') => self.display_full_help = !self.display_full_help,

//KeyCode::Char('p') => self.load_request_query_params_tab(),

Expand All @@ -267,12 +263,15 @@ impl App<'_> {
KeyCode::Left if control_pressed => self.result_horizontal_scrollbar.page_up(),
KeyCode::Right if control_pressed => self.result_horizontal_scrollbar.page_down(),

KeyCode::BackTab if shift_pressed => self.next_request_view(),
KeyCode::Tab if control_pressed => self.next_request_result_tab(),
KeyCode::Char('v') => self.next_request_view(),
KeyCode::BackTab => self.next_request_result_tab(),
KeyCode::Tab => self.next_request_param_tab(),

// Used to be ctrl + enter, but it doesn't register right on many platforms
// https://github.com/crossterm-rs/crossterm/issues/685
KeyCode::Char(' ') => self.send_request().await,
KeyCode::Enter if control_pressed => self.send_request().await,

_ => miss_input = true
}
},
Expand Down