@@ -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
132146impl 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