fortrangoingonforty/facsimile / 3f45a39

Browse files

fix some things with ctrl-f

Authored by espadonne
SHA
3f45a3911935c8c516f8d9074c375372cb0a7679
Parents
d4831b3
Tree
4463303

1 changed file

StatusFile+-
M src/ui/unified_search_module.f90 39 27
src/ui/unified_search_module.f90modified
@@ -4,6 +4,7 @@ module unified_search_module
44
     use editor_state_module, only: editor_state_t, cursor_t, sync_editor_to_pane
55
     use text_buffer_module
66
     use regex_module
7
+    use renderer_module, only: render_screen
78
     implicit none
89
     private
910
 
@@ -238,7 +239,10 @@ contains
238239
                         call search_forward(editor, buffer)
239240
                     end if
240241
 
241
-                    ! Update prompt with match count
242
+                    ! Re-render screen to show cursor at new match position
243
+                    call render_screen(buffer, editor)
244
+
245
+                    ! Update prompt with match count (redraw prompt over rendered screen)
242246
                     call build_unified_prompt(prompt, find_buffer, find_pos, replace_buffer, replace_pos)
243247
                     call display_prompt(editor, prompt, find_pos, replace_pos)
244248
                 end if
@@ -279,7 +283,33 @@ contains
279283
                     search_mode_active = .false.
280284
                     exit
281285
                 end if
282
-            else if (ch == 13 .or. ch == 10) then  ! Enter - accept current match and exit
286
+            else if (ch == 13 .or. ch == 10) then  ! Enter - find first match and exit
287
+                ! If we have a search pattern, perform search first if needed
288
+                if (find_pos > 0) then
289
+                    ! Save search pattern
290
+                    if (allocated(current_search_pattern)) deallocate(current_search_pattern)
291
+                    allocate(character(len=find_pos) :: current_search_pattern)
292
+                    current_search_pattern = find_buffer(1:find_pos)
293
+
294
+                    ! Add to search history
295
+                    call add_to_search_history(current_search_pattern)
296
+
297
+                    ! If no selection yet (haven't searched), perform the search
298
+                    if (.not. editor%cursors(editor%active_cursor)%has_selection) then
299
+                        search_mode_active = .true.
300
+                        call count_all_matches(buffer, current_search_pattern)
301
+                        call perform_search(editor, buffer, current_search_pattern)
302
+
303
+                        ! Save current parameters
304
+                        if (allocated(last_search_pattern)) deallocate(last_search_pattern)
305
+                        allocate(character(len=len(current_search_pattern)) :: last_search_pattern)
306
+                        last_search_pattern = current_search_pattern
307
+                        last_case_sensitive = case_sensitive
308
+                        last_whole_word = whole_word
309
+                        last_use_regex = use_regex
310
+                    end if
311
+                end if
312
+
283313
                 ! Move cursor to START of match (not end)
284314
                 if (editor%cursors(editor%active_cursor)%has_selection) then
285315
                     editor%cursors(editor%active_cursor)%line = &
@@ -465,29 +495,11 @@ contains
465495
             last_search_line = found_line
466496
             last_search_col = found_col
467497
 
468
-            ! DEBUG: Write to file
469
-            open(unit=99, file='/tmp/fac_debug.txt', position='append', action='write')
470
-            write(99, '(A,I0,A,I0,A,L1)') 'SEARCH: found at line=', found_line, ' col=', found_col, &
471
-                ' has_sel=', editor%cursors(editor%active_cursor)%has_selection
472
-            close(99)
473
-
474
-            ! Sync cursor to pane so pane has the updated selection
475
-            call sync_editor_to_pane(editor)
476
-
477
-            ! DEBUG: Check after sync
478
-            open(unit=99, file='/tmp/fac_debug.txt', position='append', action='write')
479
-            write(99, '(A,L1)') 'SEARCH: after sync_editor_to_pane, has_sel=', &
480
-                editor%cursors(editor%active_cursor)%has_selection
481
-            close(99)
482
-
498
+            ! Center viewport on the found match FIRST
483499
             call center_viewport_on_cursor(editor)
484
-            ! Note: render_screen should be called by the caller
485500
 
486
-            ! DEBUG: Check after centering
487
-            open(unit=99, file='/tmp/fac_debug.txt', position='append', action='write')
488
-            write(99, '(A,L1)') 'SEARCH: after center_viewport, has_sel=', &
489
-                editor%cursors(editor%active_cursor)%has_selection
490
-            close(99)
501
+            ! THEN sync cursor and viewport to pane so rendering shows updated state
502
+            call sync_editor_to_pane(editor)
491503
         end if
492504
     end subroutine perform_search
493505
 
@@ -530,11 +542,11 @@ contains
530542
             last_search_line = found_line
531543
             last_search_col = found_col
532544
 
533
-            ! Sync cursor to pane so pane has the updated selection
534
-            call sync_editor_to_pane(editor)
535
-
545
+            ! Center viewport on the found match FIRST
536546
             call center_viewport_on_cursor(editor)
537
-            ! Note: render_screen should be called by the caller
547
+
548
+            ! THEN sync cursor and viewport to pane
549
+            call sync_editor_to_pane(editor)
538550
         end if
539551
     end subroutine search_forward
540552