Skip to content

Use the working folder of the search to used it to open the result file. #345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
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 = ''
Copy link
Owner

Choose a reason for hiding this comment

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

Have you verified that ctrlsf#edit#Save still works correctly when the CWD changes? I suspect there might be issues with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your review.
I'll do more tests and I'll come back to you.

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)
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
Owner

Choose a reason for hiding this comment

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

Avoid using global variables as they're typically reserved for options. Instead, define it as s:current_pwd (similar to s:current_mode), and add a new public method ctrlsf#GetFilePath(path).

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

Expand Down