File tree Expand file tree Collapse file tree 4 files changed +54
-29
lines changed
Expand file tree Collapse file tree 4 files changed +54
-29
lines changed Original file line number Diff line number Diff line change @@ -167,9 +167,9 @@ where
167167 KeyCode :: Esc | KeyCode :: Char ( 'q' ) => Ok ( LoopControl :: Exit ( None ) ) ,
168168 KeyCode :: Tab | KeyCode :: BackTab => {
169169 if key. code == KeyCode :: Tab {
170- self . focus = self . focus . next ( ) ;
170+ self . focus_forward ( ) ;
171171 } else {
172- self . focus = self . focus . prev ( ) ;
172+ self . focus_backward ( ) ;
173173 }
174174 Ok ( LoopControl :: Continue )
175175 }
@@ -202,6 +202,52 @@ where
202202 }
203203 }
204204
205+ fn focus_forward ( & mut self ) {
206+ self . focus = match self . focus {
207+ Focus :: Worktrees => {
208+ if self . selected . is_some ( ) {
209+ Focus :: Actions
210+ } else if super :: GLOBAL_ACTIONS . is_empty ( ) {
211+ Focus :: Worktrees
212+ } else {
213+ Focus :: GlobalActions
214+ }
215+ }
216+ Focus :: Actions => Focus :: Worktrees ,
217+ Focus :: GlobalActions => {
218+ if self . selected . is_some ( ) {
219+ Focus :: Actions
220+ } else {
221+ Focus :: Worktrees
222+ }
223+ }
224+ } ;
225+ }
226+
227+ fn focus_backward ( & mut self ) {
228+ self . focus = match self . focus {
229+ Focus :: Worktrees => {
230+ if self . selected . is_some ( ) {
231+ Focus :: Actions
232+ } else if super :: GLOBAL_ACTIONS . is_empty ( ) {
233+ Focus :: Worktrees
234+ } else {
235+ Focus :: GlobalActions
236+ }
237+ }
238+ Focus :: Actions => {
239+ if self . selected . is_some ( ) {
240+ Focus :: Worktrees
241+ } else if super :: GLOBAL_ACTIONS . is_empty ( ) {
242+ Focus :: Actions
243+ } else {
244+ Focus :: GlobalActions
245+ }
246+ }
247+ Focus :: GlobalActions => Focus :: Worktrees ,
248+ } ;
249+ }
250+
205251 fn handle_enter ( & mut self ) -> Result < LoopControl > {
206252 match self . focus {
207253 Focus :: Worktrees => {
Original file line number Diff line number Diff line change @@ -36,24 +36,6 @@ pub(crate) enum Focus {
3636 GlobalActions ,
3737}
3838
39- impl Focus {
40- pub ( crate ) fn next ( self ) -> Self {
41- match self {
42- Focus :: Worktrees => Focus :: Actions ,
43- Focus :: Actions => Focus :: GlobalActions ,
44- Focus :: GlobalActions => Focus :: Worktrees ,
45- }
46- }
47-
48- pub ( crate ) fn prev ( self ) -> Self {
49- match self {
50- Focus :: Worktrees => Focus :: GlobalActions ,
51- Focus :: Actions => Focus :: Worktrees ,
52- Focus :: GlobalActions => Focus :: Actions ,
53- }
54- }
55- }
56-
5739pub ( crate ) const GLOBAL_ACTIONS : [ & str ; 2 ] = [ "Create worktree" , "Cd to root dir" ] ;
5840
5941#[ derive( Clone , Debug , PartialEq , Eq ) ]
Original file line number Diff line number Diff line change @@ -203,8 +203,8 @@ fn create_action_adds_new_worktree() -> Result<()> {
203203 let backend = TestBackend :: new ( 60 , 18 ) ;
204204 let terminal = Terminal :: new ( backend) ?;
205205 let events = StubEvents :: new ( vec ! [
206- key( KeyCode :: Tab ) ,
207- key( KeyCode :: Tab ) ,
206+ key( KeyCode :: Up ) ,
207+ key( KeyCode :: Up ) ,
208208 key( KeyCode :: Enter ) ,
209209 char_key( 'n' ) ,
210210 char_key( 'e' ) ,
@@ -248,8 +248,8 @@ fn cancelling_create_leaves_state_unchanged() -> Result<()> {
248248 let backend = TestBackend :: new ( 60 , 18 ) ;
249249 let terminal = Terminal :: new ( backend) ?;
250250 let events = StubEvents :: new ( vec ! [
251- key( KeyCode :: Tab ) ,
252- key( KeyCode :: Tab ) ,
251+ key( KeyCode :: Up ) ,
252+ key( KeyCode :: Up ) ,
253253 key( KeyCode :: Enter ) ,
254254 key( KeyCode :: Esc ) ,
255255 key( KeyCode :: Esc ) ,
@@ -277,9 +277,7 @@ fn cd_to_root_global_action_exits() -> Result<()> {
277277 let backend = TestBackend :: new ( 40 , 12 ) ;
278278 let terminal = Terminal :: new ( backend) ?;
279279 let events = StubEvents :: new ( vec ! [
280- key( KeyCode :: Tab ) ,
281- key( KeyCode :: Tab ) ,
282- key( KeyCode :: Right ) ,
280+ key( KeyCode :: Up ) ,
283281 key( KeyCode :: Enter ) ,
284282 ] ) ;
285283
@@ -328,7 +326,6 @@ fn up_from_top_after_tabbing_picks_last_global_action() -> Result<()> {
328326 let backend = TestBackend :: new ( 40 , 12 ) ;
329327 let terminal = Terminal :: new ( backend) ?;
330328 let events = StubEvents :: new ( vec ! [
331- key( KeyCode :: Tab ) ,
332329 key( KeyCode :: Tab ) ,
333330 key( KeyCode :: Tab ) ,
334331 key( KeyCode :: Up ) ,
Original file line number Diff line number Diff line change @@ -147,7 +147,7 @@ impl Snapshot {
147147
148148 let actions = Paragraph :: new ( Line :: from ( spans) ) . block (
149149 Block :: default ( )
150- . title ( "Worktree Actions" )
150+ . title ( "Worktree Actions (Tab key) " )
151151 . borders ( Borders :: ALL ) ,
152152 ) ;
153153 frame. render_widget ( actions, detail_chunks[ 1 ] ) ;
You can’t perform that action at this time.
0 commit comments