Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
32 changes: 24 additions & 8 deletions autoload/ctrlsf.vim
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func! s:ExecSearch(args, override = v:false) abort
return -1
endif

let g:ctrlsf_pwd = getcwd()

call ctrlsf#profile#Sample("StartSearch")
if g:ctrlsf_search_mode ==# 'sync'
call s:DoSearchSync(a:args)
Expand Down Expand Up @@ -426,21 +428,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 Expand Up @@ -484,13 +493,20 @@ endf
func! s:PreviewFile(file, lnum, col, follow) abort
call ctrlsf#preview#OpenPreviewWindow()

if !exists('b:ctrlsf_file') || empty(b:ctrlsf_file) || b:ctrlsf_file !=# a:file
let b:ctrlsf_file = a:file
let file_path = ''
if isabsolutepath(a:file)
let file_path = a:file
else
let file_path = g:ctrlsf_pwd . '/' . a:file
endif

if !exists('b:ctrlsf_file') || empty(b:ctrlsf_file) || b:ctrlsf_file !=# file_path
let b:ctrlsf_file = file_path

call ctrlsf#buf#WriteFile(a:file)
call ctrlsf#buf#WriteFile(file_path)

" trigger filetypedetect (syntax highlight)
exec 'doau filetypedetect BufRead ' . fnameescape(a:file)
exec 'doau filetypedetect BufRead ' . fnameescape(file_path)
endif

call ctrlsf#win#MoveCursorCentral(a:lnum, a:col)
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