Skip to content

Commit 38634d2

Browse files
committed
Fix switching screens while in editing mode
1 parent b816b61 commit 38634d2

2 files changed

Lines changed: 25 additions & 19 deletions

File tree

cli/src/tui/components/screen.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,14 @@ impl Screen {
6161
self.param_idx.current()
6262
}
6363

64-
fn help_text_mode(&self) -> HelpTextMode {
65-
let is_in_editing_mode = self
66-
.parameters
64+
pub fn is_in_editing_mode(&self) -> bool {
65+
self.parameters
6766
.iter()
68-
.any(|p| p.input_mode == InputMode::Editing);
67+
.any(|p| p.input_mode == InputMode::Editing)
68+
}
6969

70-
if is_in_editing_mode {
70+
fn help_text_mode(&self) -> HelpTextMode {
71+
if self.is_in_editing_mode() {
7172
HelpTextMode::EditMode
7273
} else {
7374
HelpTextMode::NormalMode

cli/src/tui/mod.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,20 @@ impl App {
127127
});
128128
do_tick
129129
}
130+
131+
fn current_screen_mut(&mut self) -> &mut Screen {
132+
let screen_idx = self.screen_idx.current();
133+
&mut self.screens[screen_idx]
134+
}
135+
136+
fn current_screen(&self) -> &Screen {
137+
let screen_idx = self.screen_idx.current();
138+
&self.screens[screen_idx]
139+
}
140+
141+
fn can_switch_screens(&self) -> bool {
142+
self.screens.len() > 1 && !self.current_screen().is_in_editing_mode()
143+
}
130144
}
131145

132146
impl App {
@@ -144,32 +158,26 @@ impl App {
144158
return;
145159
}
146160
KeyCode::Right => {
147-
if self.screens.len() > 1 {
148-
debug!("bef: {}", self.screen_idx.current());
161+
if self.can_switch_screens() {
149162
self.screen_idx.forward();
150163
actions.push(Action::SetMode(
151164
self.screens[self.screen_idx.current()].accel_mode,
152165
));
153-
debug!("af: {}", self.screen_idx.current());
154166
}
155167
}
156168
KeyCode::Left => {
157-
if self.screens.len() > 1 {
158-
debug!("bef: {}", self.screen_idx.current());
169+
if self.can_switch_screens() {
159170
self.screen_idx.back();
160171
actions.push(Action::SetMode(
161172
self.screens[self.screen_idx.current()].accel_mode,
162173
));
163-
debug!("af: {}", self.screen_idx.current());
164174
}
165175
}
166176
_ => {}
167177
}
168178
}
169179

170-
let screen_idx = self.screen_idx.current();
171-
let screen = &mut self.screens[screen_idx];
172-
screen.handle_event(event, actions);
180+
self.current_screen_mut().handle_event(event, actions);
173181
}
174182

175183
fn update(&mut self, actions: &mut Vec<action::Action>) {
@@ -183,15 +191,12 @@ impl App {
183191
self.context.get_mut().reset_current_parameters();
184192
}
185193

186-
let screen_idx = self.screen_idx.current();
187-
let screen = &mut self.screens[screen_idx];
188-
screen.update(&action);
194+
self.current_screen_mut().update(&action);
189195
}
190196
}
191197

192198
fn draw(&self, frame: &mut ratatui::Frame, area: ratatui::prelude::Rect) {
193-
let screen_idx = self.screen_idx.current();
194-
self.screens[screen_idx].draw(frame, area);
199+
self.current_screen().draw(frame, area);
195200
}
196201
}
197202

0 commit comments

Comments
 (0)