Skip to content

Experimental Features: actions.open_file.relative_path #2819

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

Closed
alex-courtis opened this issue Jul 7, 2024 · 11 comments · Fixed by #2995
Closed

Experimental Features: actions.open_file.relative_path #2819

alex-courtis opened this issue Jul 7, 2024 · 11 comments · Fixed by #2995

Comments

@alex-courtis
Copy link
Member

alex-courtis commented Jul 7, 2024

Experimental Features

nvim-tree has experimental features, previews of new functionality that will become default or optional functionality.

Please try these out and reply with your experiences. If you encounter a problem, please raise a bug report and indicate the experimental feature you are using.

#2127 Open Buffers With Relative Path (#2805)

Buffers opened by nvim-tree will use with relative paths instead of absolute.
Execute :ls to see the paths of all open buffers.
:help nvim-tree.experimental.actions.open_file.relative_path

Enable:

      experimental = {
        actions = {
          open_file = {
            relative_path = true,
          },
        },
      },

2024 07 07 introduced, false by default

@epheien
Copy link
Collaborator

epheien commented Jul 7, 2024

I have been using this feature here for a while without any issues, but my usage scenario is relatively simple.

As long as the absolute path of the file is converted to a relative path before specifying the: edit (etc.) command, it should theoretically be sufficiently secure. Based on this, I rechecked the code and found that there is an area that needs to be fixed.

In local function open_in_new_window(filename, mode) function, there is a problem with window jumping after converting to a relative path.

  if (mode == "preview" or mode == "preview_no_picker") and view.View.float.enable then
    -- ignore "WinLeave" autocmd on preview
    -- because the registered "WinLeave"
    -- will kill the floating window immediately
    set_current_win_no_autocmd(target_winid, { "WinLeave", "BufEnter" })
  else
    set_current_win_no_autocmd(target_winid, { "BufEnter" })
  end

  pcall(vim.api.nvim_cmd, command, { output = false })
  lib.set_target_win()

Can perform simple steps to reproduce this problem:

:NvimTreeOpen
" jump to a window to open file
:lcd ..
" jump to NvimTree window and select a file to open

This will open an incorrect path.

I just make a PR to fix it.

alex-courtis pushed a commit that referenced this issue Jul 7, 2024
…ing change directory (#2820)

fix issue with the description of epheien in #2819

Co-authored-by: eph <[email protected]>
@alex-courtis
Copy link
Member Author

Thanks @epheien

I did expect several issues like these. We will fix them.

@paulodiovani
Copy link

I was looking for this. Thanks.

I'll be using from now on and report if I find any issue.

@alex-courtis
Copy link
Member Author

This is looking good... over a month and no issues.

Are you happy to finish the experiment and make this the one and only way to open files @epheien ?

@wrldspawn
Copy link

This feature doesn't work on Windows at all. Other things like Telescope can open files relatively just fine on Windows, but not nvim-tree with this feature enabled.

@alex-courtis
Copy link
Member Author

Many thanks for testing this one @wrldspawn , we don't have any means of testing windows.

What happens when this feature is enabled? Is there a stack?

I'd be grateful if you could raise a bug report so that I can attempt a fix for you to test.

@bibliothek
Copy link

FWIW, I activated the feature on Windows. Works as expected for me 👍 🎉

@alex-courtis alex-courtis reopened this Nov 7, 2024
@alex-courtis
Copy link
Member Author

FWIW, I activated the feature on Windows. Works as expected for me 👍 🎉

Thanks for letting us know.

Proposal:

Does that sound reasonable @gegoune ?

@gegoune
Copy link
Collaborator

gegoune commented Nov 8, 2024

Sounds good, @alex-courtis. It's been 'out there' for long enough and interested parties were using it without issues. I haven't personally so can't really add much to the issue, sorry.

@alex-courtis
Copy link
Member Author

Thank you!

@alex-courtis
Copy link
Member Author

actions.open_file.relative_path is now enabled by default.

@alex-courtis alex-courtis unpinned this issue Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants