Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions autoload/ctrlsf.vim
Original file line number Diff line number Diff line change
Expand Up @@ -426,21 +426,28 @@ func! s:OpenFileInWindow(file, lnum, col, mode, split) abort
endif
endif

let file_path = ''
if isabsolutepath(a:file)
let file_path = a:file
else
let file_path = g:ctrlsf_pwd . '/' . a:file
endif

let target_winnr = ctrlsf#win#FindTargetWindow(a:file)
if target_winnr == 0
exec 'silent split ' . fnameescape(a:file)
exec 'silent split ' . fnameescape(file_path)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Canonicalize window lookup with the same path you open

This change opens buffers using file_path (often absolute) but s:OpenFileInWindow() still identifies existing targets with the original a:file value. When search results are relative (default), the first jump opens an absolute buffer name and subsequent jumps can no longer match that buffer by a:file, so CtrlSF may reopen/re-split the same file instead of reusing the current window. The regression is visible by jumping to the same match repeatedly after one search; path matching should use the same canonical form for lookup and open/edit.

Useful? React with 👍 / 👎.

else
exec target_winnr . 'wincmd w'

if bufname('%') !=# a:file
if a:split || (&modified && !&hidden)
if a:split == 2
exec 'silent vertical split ' . fnameescape(a:file)
exec 'silent vertical split ' . fnameescape(file_path)
else
exec 'silent split ' . fnameescape(a:file)
exec 'silent split ' . fnameescape(file_path)
endif
else
exec 'silent edit ' . fnameescape(a:file)
exec 'silent edit ' . fnameescape(file_path)
endif
endif
endif
Expand Down
1 change: 1 addition & 0 deletions autoload/ctrlsf/backend.vim
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ let s:backend_args_map = {
" BuildCommand()
"
func! s:BuildCommand(args, for_shell) abort
let g:ctrlsf_pwd = getcwd()
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to verify the scope of the g:ctrlsf_pwd variable. I think this variable should remain constant whenever the ctrlsf command is invoked; therefore, it would be more appropriate to assign it within s:ExecSearch. Since s:BuildCommand is intended as a utility function, it shouldn't be responsible for this assignment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I have adapted the code and redone my testing.

let tokens = []
let runner = ctrlsf#backend#Runner()

Expand Down
7 changes: 6 additions & 1 deletion autoload/ctrlsf/edit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ endf
" s:SaveFile()
"
func! s:SaveFile(orig, modi) abort
let file = a:orig.filename
let file = ''
if isabsolutepath(a:orig.filename)
let file = a:orig.filename
else
let file = g:ctrlsf_pwd . '/' . a:orig.filename
endif

try
let buffer = readfile(file)
Expand Down