@@ -6315,7 +6315,8 @@ contains |
| 6315 | 6315 | subroutine navigate_to_workspace_symbol(editor, buffer, symbol, should_quit) |
| 6316 | 6316 | use workspace_symbols_panel_module, only: workspace_symbol_t |
| 6317 | 6317 | use jump_stack_module, only: push_jump_location |
| 6318 | | - use editor_state_module, only: switch_to_tab |
| 6318 | + use editor_state_module, only: switch_to_tab, create_tab, sync_pane_to_editor, sync_editor_to_pane |
| 6319 | + use text_buffer_module, only: buffer_load_file, copy_buffer |
| 6319 | 6320 | type(editor_state_t), intent(inout) :: editor |
| 6320 | 6321 | type(buffer_t), intent(inout) :: buffer |
| 6321 | 6322 | type(workspace_symbol_t), intent(in) :: symbol |
@@ -6354,17 +6355,44 @@ contains |
| 6354 | 6355 | end if |
| 6355 | 6356 | end do |
| 6356 | 6357 | |
| 6357 | | - ! File not open - for now, just navigate in current file if it's the same |
| 6358 | | - ! TODO: Implement opening file in new tab when file differs |
| 6359 | | - if (allocated(editor%filename)) then |
| 6360 | | - if (trim(editor%filename) == trim(filepath)) then |
| 6361 | | - ! Same file - just navigate |
| 6358 | + ! File not open - create a new tab and load the file |
| 6359 | + call create_tab(editor, filepath) |
| 6360 | + |
| 6361 | + ! Load file content into the new tab's buffer |
| 6362 | + block |
| 6363 | + integer :: status, new_tab_idx |
| 6364 | + |
| 6365 | + new_tab_idx = size(editor%tabs) ! The tab we just created |
| 6366 | + |
| 6367 | + call buffer_load_file(editor%tabs(new_tab_idx)%buffer, filepath, status) |
| 6368 | + |
| 6369 | + if (status == 0) then |
| 6370 | + ! File loaded successfully |
| 6371 | + ! Copy buffer to the pane's buffer |
| 6372 | + if (allocated(editor%tabs(new_tab_idx)%panes)) then |
| 6373 | + call copy_buffer(editor%tabs(new_tab_idx)%panes(1)%buffer, editor%tabs(new_tab_idx)%buffer) |
| 6374 | + end if |
| 6375 | + |
| 6376 | + ! Switch to the new tab |
| 6377 | + call switch_to_tab(editor, new_tab_idx) |
| 6378 | + |
| 6379 | + ! Sync the pane to editor state (this updates editor%cursors, etc.) |
| 6380 | + call sync_pane_to_editor(editor, new_tab_idx, 1) |
| 6381 | + |
| 6382 | + ! Navigate to the symbol's position |
| 6362 | 6383 | editor%cursors(editor%active_cursor)%line = symbol%line + 1 ! LSP is 0-based |
| 6363 | 6384 | editor%cursors(editor%active_cursor)%column = symbol%character + 1 |
| 6364 | 6385 | editor%cursors(editor%active_cursor)%desired_column = symbol%character + 1 |
| 6365 | 6386 | editor%viewport_line = max(1, symbol%line + 1 - editor%screen_rows / 2) |
| 6387 | + |
| 6388 | + ! Sync editor state back to pane |
| 6389 | + call sync_editor_to_pane(editor) |
| 6390 | + else |
| 6391 | + ! File load failed - could show error message |
| 6392 | + ! For now, just don't navigate |
| 6393 | + continue |
| 6366 | 6394 | end if |
| 6367 | | - end if |
| 6395 | + end block |
| 6368 | 6396 | end subroutine navigate_to_workspace_symbol |
| 6369 | 6397 | |
| 6370 | 6398 | end module command_handler_module |