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
4
     use editor_state_module, only: editor_state_t, cursor_t, sync_editor_to_pane
4
     use editor_state_module, only: editor_state_t, cursor_t, sync_editor_to_pane
5
     use text_buffer_module
5
     use text_buffer_module
6
     use regex_module
6
     use regex_module
7
+    use renderer_module, only: render_screen
7
     implicit none
8
     implicit none
8
     private
9
     private
9
 
10
 
@@ -238,7 +239,10 @@ contains
238
                         call search_forward(editor, buffer)
239
                         call search_forward(editor, buffer)
239
                     end if
240
                     end if
240
 
241
 
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)
242
                     call build_unified_prompt(prompt, find_buffer, find_pos, replace_buffer, replace_pos)
246
                     call build_unified_prompt(prompt, find_buffer, find_pos, replace_buffer, replace_pos)
243
                     call display_prompt(editor, prompt, find_pos, replace_pos)
247
                     call display_prompt(editor, prompt, find_pos, replace_pos)
244
                 end if
248
                 end if
@@ -279,7 +283,33 @@ contains
279
                     search_mode_active = .false.
283
                     search_mode_active = .false.
280
                     exit
284
                     exit
281
                 end if
285
                 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
+
283
                 ! Move cursor to START of match (not end)
313
                 ! Move cursor to START of match (not end)
284
                 if (editor%cursors(editor%active_cursor)%has_selection) then
314
                 if (editor%cursors(editor%active_cursor)%has_selection) then
285
                     editor%cursors(editor%active_cursor)%line = &
315
                     editor%cursors(editor%active_cursor)%line = &
@@ -465,29 +495,11 @@ contains
465
             last_search_line = found_line
495
             last_search_line = found_line
466
             last_search_col = found_col
496
             last_search_col = found_col
467
 
497
 
468
-            ! DEBUG: Write to file
498
+            ! Center viewport on the found match FIRST
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
-
483
             call center_viewport_on_cursor(editor)
499
             call center_viewport_on_cursor(editor)
484
-            ! Note: render_screen should be called by the caller
485
 
500
 
486
-            ! DEBUG: Check after centering
501
+            ! THEN sync cursor and viewport to pane so rendering shows updated state
487
-            open(unit=99, file='/tmp/fac_debug.txt', position='append', action='write')
502
+            call sync_editor_to_pane(editor)
488
-            write(99, '(A,L1)') 'SEARCH: after center_viewport, has_sel=', &
489
-                editor%cursors(editor%active_cursor)%has_selection
490
-            close(99)
491
         end if
503
         end if
492
     end subroutine perform_search
504
     end subroutine perform_search
493
 
505
 
@@ -530,11 +542,11 @@ contains
530
             last_search_line = found_line
542
             last_search_line = found_line
531
             last_search_col = found_col
543
             last_search_col = found_col
532
 
544
 
533
-            ! Sync cursor to pane so pane has the updated selection
545
+            ! Center viewport on the found match FIRST
534
-            call sync_editor_to_pane(editor)
535
-
536
             call center_viewport_on_cursor(editor)
546
             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)
538
         end if
550
         end if
539
     end subroutine search_forward
551
     end subroutine search_forward
540
 
552