fortrangoingonforty/fuss / 0da432f

Browse files

better fuzzy jump

Authored by espadonne
SHA
0da432f4293996909a608dbfbef42ceeb52f1bbc
Parents
dada48b
Tree
3fd82e3

2 changed files

StatusFile+-
M src/display_module.f90 1 1
M src/fuss_main.f90 43 3
src/display_module.f90modified
@@ -190,7 +190,7 @@ contains
190190
                          achar(27) // '[31m✗' // achar(27) // '[0m=modified ' // &
191191
                          achar(27) // '[90m✗' // achar(27) // '[0m=untracked ' // &
192192
                          achar(27) // '[34m↓' // achar(27) // '[0m=incoming'
193
-            print '(A)', 'Keys: j/k/↑/↓:nav | ←/→:nav tree | space:toggle | .:hide-dots | alt-g:git-mode | q:quit'
193
+            print '(A)', 'Keys: j/k/↑/↓:nav | ←/→:nav tree | space:toggle | .:hide-dots | alt-g:git-mode | ctrl-q:quit'
194194
         end if
195195
 
196196
         ! Don't free tree - it's owned by interactive_mode
src/fuss_main.f90modified
@@ -299,11 +299,11 @@ contains
299299
             prev_selected = selected
300300
             prev_viewport = viewport_offset
301301
 
302
-            ! Check search timeout (1 second)
302
+            ! Check search timeout (0.5 seconds)
303303
             if (search_length > 0) then
304304
                 call system_clock(current_tick)
305
-                ! Check if 1 second has elapsed (clock_rate ticks per second)
306
-                if (current_tick - last_search_tick > clock_rate) then
305
+                ! Check if 0.5 seconds has elapsed (clock_rate/2 ticks)
306
+                if (current_tick - last_search_tick > clock_rate / 2) then
307307
                     search_length = 0
308308
                     search_buffer = ''
309309
                     needs_full_redraw = .true.
@@ -363,6 +363,21 @@ contains
363363
                 if ((key >= 'a' .and. key <= 'z') .or. &
364364
                     ((key >= 'E' .and. key <= 'Z') .or. (key >= '0' .and. key <= '9')) .or. &
365365
                     key == '_' .or. key == '-' .or. key == '.') then
366
+
367
+                    ! Check if timeout elapsed since last keypress - if so, start fresh search
368
+                    if (search_length > 0) then
369
+                        call system_clock(current_tick)
370
+                        if (current_tick - last_search_tick > clock_rate / 2) then
371
+                            ! Timeout elapsed (0.5 seconds) - clear buffer and start new search
372
+                            search_length = 0
373
+                            search_buffer = ''
374
+                            ! DEBUG
375
+                            open(99, file='/tmp/fuss_debug.log', position='append')
376
+                            write(99, '(A)') 'TIMEOUT: Starting fresh search (0.5s elapsed)'
377
+                            close(99)
378
+                        end if
379
+                    end if
380
+
366381
                     ! Add to search buffer
367382
                     if (search_length < 32) then
368383
                         search_length = search_length + 1
@@ -686,6 +701,8 @@ contains
686701
                     ! In normal mode: q quits the application
687702
                     running = .false.
688703
                 end if
704
+            case (achar(17))  ! Ctrl-Q - force quit from any mode
705
+                running = .false.
689706
             case default
690707
                 ! Unhandled keys - do nothing
691708
                 continue
@@ -1512,6 +1529,7 @@ contains
15121529
 
15131530
     subroutine fuzzy_jump_to_match(items, n_items, pattern, selected)
15141531
         ! Jump to first item that fuzzy matches the pattern
1532
+        ! Prioritizes matching item names (basename) over full paths
15151533
         ! Searches from NEXT position (skips current item to allow cycling)
15161534
         type(selectable_item), intent(in) :: items(:)
15171535
         integer, intent(in) :: n_items
@@ -1523,6 +1541,28 @@ contains
15231541
         start_pos = selected + 1
15241542
         if (start_pos > n_items) start_pos = 1
15251543
 
1544
+        ! PASS 1: Try to match item NAME first (e.g., "src" matches "src/" before "src/file.f90")
1545
+        ! Search from next position forward
1546
+        do i = start_pos, n_items
1547
+            if (associated(items(i)%node)) then
1548
+                if (fuzzy_match(pattern, items(i)%node%name)) then
1549
+                    selected = i
1550
+                    return
1551
+                end if
1552
+            end if
1553
+        end do
1554
+
1555
+        ! Wrap around: search from beginning to current position (inclusive)
1556
+        do i = 1, selected
1557
+            if (associated(items(i)%node)) then
1558
+                if (fuzzy_match(pattern, items(i)%node%name)) then
1559
+                    selected = i
1560
+                    return
1561
+                end if
1562
+            end if
1563
+        end do
1564
+
1565
+        ! PASS 2: If no name match, try matching full path
15261566
         ! Search from next position forward
15271567
         do i = start_pos, n_items
15281568
             if (fuzzy_match(pattern, items(i)%path)) then