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

Next and previous word handling #109

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
Loading