Skip to content

Commit

Permalink
support backtab in chart config pane (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
miraclx authored Feb 26, 2021
1 parent 8199a62 commit b1e0880
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ pub fn handle_keys_configure_chart(keycode: KeyCode, mut app: &mut app::App) {
let config = app.stocks[app.current_tab].chart_config_mut();
config.tab();
}
KeyCode::BackTab => {
let config = app.stocks[app.current_tab].chart_config_mut();
config.back_tab();
}
KeyCode::Enter => {
let time_frame = app.stocks[app.current_tab].time_frame;
let config = app.stocks[app.current_tab].chart_config_mut();
Expand Down
17 changes: 14 additions & 3 deletions src/widget/chart_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,31 @@ impl ChartConfigurationState {
input_field.pop();
}

pub fn tab(&mut self) {
fn get_tab_artifacts(&mut self) -> Option<(&mut usize, usize)> {
let tab_field = match self.selection {
Some(Selection::KagiReversalType) => &mut self.input.kagi_reversal_type,
Some(Selection::KagiPriceType) => &mut self.input.kagi_price_type,
_ => return,
_ => return None,
};

let mod_value = match self.selection {
Some(Selection::KagiReversalType) => 2,
Some(Selection::KagiPriceType) => 2,
_ => 1,
};
Some((tab_field, mod_value))
}

pub fn tab(&mut self) {
if let Some((tab_field, mod_value)) = self.get_tab_artifacts() {
*tab_field = (*tab_field + 1) % mod_value;
}
}

*tab_field = (*tab_field + 1) % mod_value;
pub fn back_tab(&mut self) {
if let Some((tab_field, mod_value)) = self.get_tab_artifacts() {
*tab_field = (*tab_field + mod_value - 1) % mod_value;
}
}

pub fn enter(&mut self, time_frame: TimeFrame) {
Expand Down

0 comments on commit b1e0880

Please sign in to comment.