Skip to content

Experimental Features: actions.open_file.relative_path #2819

Closed
@alex-courtis

Description

@alex-courtis
Member

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

Activity

pinned this issue on Jul 7, 2024
epheien

epheien commented on Jul 7, 2024

@epheien
Collaborator

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.

added a commit that references this issue on Jul 7, 2024

fix(#2819): experimental.actions.open_file.relative_path issue follow…

12a9a99
alex-courtis

alex-courtis commented on Jul 7, 2024

@alex-courtis
MemberAuthor

Thanks @epheien

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

paulodiovani

paulodiovani commented on Jul 26, 2024

@paulodiovani

I was looking for this. Thanks.

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

alex-courtis

alex-courtis commented on Aug 10, 2024

@alex-courtis
MemberAuthor

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

wrldspawn commented on Sep 23, 2024

@wrldspawn

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

alex-courtis commented on Sep 27, 2024

@alex-courtis
MemberAuthor

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.

17 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @paulodiovani@alex-courtis@epheien@bibliothek@gegoune

      Issue actions

        Experimental Features: actions.open_file.relative_path · Issue #2819 · nvim-tree/nvim-tree.lua