@@ -4,6 +4,7 @@ module unified_search_module |
| 4 | 4 | use editor_state_module, only: editor_state_t, cursor_t, sync_editor_to_pane |
| 5 | 5 | use text_buffer_module |
| 6 | 6 | use regex_module |
| 7 | + use renderer_module, only: render_screen |
| 7 | 8 | implicit none |
| 8 | 9 | private |
| 9 | 10 | |
@@ -238,7 +239,10 @@ contains |
| 238 | 239 | call search_forward(editor, buffer) |
| 239 | 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 | 246 | call build_unified_prompt(prompt, find_buffer, find_pos, replace_buffer, replace_pos) |
| 243 | 247 | call display_prompt(editor, prompt, find_pos, replace_pos) |
| 244 | 248 | end if |
@@ -279,7 +283,33 @@ contains |
| 279 | 283 | search_mode_active = .false. |
| 280 | 284 | exit |
| 281 | 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 | 313 | ! Move cursor to START of match (not end) |
| 284 | 314 | if (editor%cursors(editor%active_cursor)%has_selection) then |
| 285 | 315 | editor%cursors(editor%active_cursor)%line = & |
@@ -465,29 +495,11 @@ contains |
| 465 | 495 | last_search_line = found_line |
| 466 | 496 | last_search_col = found_col |
| 467 | 497 | |
| 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 |
| 483 | 499 | call center_viewport_on_cursor(editor) |
| 484 | | - ! Note: render_screen should be called by the caller |
| 485 | 500 | |
| 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) |
| 491 | 503 | end if |
| 492 | 504 | end subroutine perform_search |
| 493 | 505 | |
@@ -530,11 +542,11 @@ contains |
| 530 | 542 | last_search_line = found_line |
| 531 | 543 | last_search_col = found_col |
| 532 | 544 | |
| 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 |
| 536 | 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 | 550 | end if |
| 539 | 551 | end subroutine search_forward |
| 540 | 552 | |