Skip to content

Commit

Permalink
Merge pull request #109 from matthewmturner/feat/more-keys
Browse files Browse the repository at this point in the history
Next and previous word handling
  • Loading branch information
matthewmturner authored Aug 28, 2024
2 parents f438f3d + 517d36d commit b77a59e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/app/handlers/flightsql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ pub fn normal_mode_handler(app: &mut App, key: KeyEvent) {

pub fn editable_handler(app: &mut App, key: KeyEvent) {
match (key.code, key.modifiers) {
(KeyCode::Left, KeyModifiers::ALT) => app.state.sql_tab.previous_word(),
(KeyCode::Right, KeyModifiers::ALT) => app.state.sql_tab.next_word(),
(KeyCode::Esc, _) => app.state.flightsql_tab.exit_edit(),
_ => app.state.flightsql_tab.update_editor_content(key),
}
Expand Down
2 changes: 2 additions & 0 deletions src/app/handlers/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ pub fn normal_mode_handler(app: &mut App, key: KeyEvent) {

pub fn editable_handler(app: &mut App, key: KeyEvent) {
match (key.code, key.modifiers) {
(KeyCode::Left, KeyModifiers::ALT) => app.state.sql_tab.previous_word(),
(KeyCode::Right, KeyModifiers::ALT) => app.state.sql_tab.next_word(),
(KeyCode::Esc, _) => app.state.sql_tab.exit_edit(),
(KeyCode::Enter, KeyModifiers::CONTROL) => {
let query = app.state.sql_tab.editor().lines().join("");
Expand Down
11 changes: 11 additions & 0 deletions src/app/state/tabs/flightsql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,15 @@ impl<'app> FlightSQLTabState<'app> {
pub fn query(&self) -> &Option<FlightSQLQuery> {
&self.query
}

// TODO: Create Editor struct and move this there
pub fn next_word(&mut self) {
self.editor
.move_cursor(tui_textarea::CursorMove::WordForward)
}

// TODO: Create Editor struct and move this there
pub fn previous_word(&mut self) {
self.editor.move_cursor(tui_textarea::CursorMove::WordBack)
}
}
27 changes: 9 additions & 18 deletions src/app/state/tabs/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ pub struct SQLTabState<'app> {
editor: TextArea<'app>,
editor_editable: bool,
query: Option<Query>,
// query_results: Option<Vec<RecordBatch>>,
query_results_state: Option<RefCell<TableState>>,
// query_error: Option<String>,
}

impl<'app> SQLTabState<'app> {
Expand All @@ -107,9 +105,7 @@ impl<'app> SQLTabState<'app> {
editor: textarea,
editor_editable: false,
query: None,
// query_results: None,
query_results_state: None,
// query_error: None,
}
}

Expand All @@ -121,14 +117,6 @@ impl<'app> SQLTabState<'app> {
self.query_results_state = Some(RefCell::new(TableState::default()));
}

// pub fn query_error(&self) -> &Option<String> {
// &self.query_error
// }

// pub fn set_query_error(&mut self, error: String) {
// self.query_error = Some(error);
// }

pub fn editor(&self) -> TextArea {
// TODO: Figure out how to do this without clone. Probably need logic in handler to make
// updates to the Widget and then pass a ref
Expand Down Expand Up @@ -174,11 +162,14 @@ impl<'app> SQLTabState<'app> {
&self.query
}

// pub fn set_query_results(&mut self, query_results: Vec<RecordBatch>) {
// self.query_results = Some(query_results);
// }
// TODO: Create Editor struct and move this there
pub fn next_word(&mut self) {
self.editor
.move_cursor(tui_textarea::CursorMove::WordForward)
}

// pub fn query_results(&self) -> &Option<Vec<RecordBatch>> {
// &self.query_results
// }
// TODO: Create Editor struct and move this there
pub fn previous_word(&mut self) {
self.editor.move_cursor(tui_textarea::CursorMove::WordBack)
}
}

0 comments on commit b77a59e

Please sign in to comment.