fortrangoingonforty/facsimile / bdd482b

Browse files

Enable cross-file navigation in Workspace Symbols - automatically opens new tabs for symbols in different files

Authored by espadonne
SHA
bdd482bb3bc153a4341a3a2c1dd971e211971c55
Parents
e03ce0c
Tree
6db8074

1 changed file

StatusFile+-
M src/commands/command_handler_module.f90 35 7
src/commands/command_handler_module.f90modified
@@ -6315,7 +6315,8 @@ contains
63156315
     subroutine navigate_to_workspace_symbol(editor, buffer, symbol, should_quit)
63166316
         use workspace_symbols_panel_module, only: workspace_symbol_t
63176317
         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
63196320
         type(editor_state_t), intent(inout) :: editor
63206321
         type(buffer_t), intent(inout) :: buffer
63216322
         type(workspace_symbol_t), intent(in) :: symbol
@@ -6354,17 +6355,44 @@ contains
63546355
             end if
63556356
         end do
63566357
 
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
63626383
                 editor%cursors(editor%active_cursor)%line = symbol%line + 1  ! LSP is 0-based
63636384
                 editor%cursors(editor%active_cursor)%column = symbol%character + 1
63646385
                 editor%cursors(editor%active_cursor)%desired_column = symbol%character + 1
63656386
                 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
63666394
             end if
6367
-        end if
6395
+        end block
63686396
     end subroutine navigate_to_workspace_symbol
63696397
 
63706398
 end module command_handler_module