Skip to content

fix: Preventing removal of necessary root separator on Windows #986

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

Merged
merged 1 commit into from
Jun 11, 2023

Conversation

Aeceon
Copy link
Contributor

@Aeceon Aeceon commented Jun 11, 2023

This fixes #985

When a root path was supplied as an argument to the Neotree command or to execute on Windows, the necessary separator was removed. ":Neotree C:", for instance, would become "C:" and this resulted in an empty listing.

Instead of testing if the length of args.dir is greater than 1, this now compares it to 3 on Windows while remaining 1 on other operating systems, including WSL.

   -- Root paths on Windows have 3 characters ("C:\")
    local root_len = vim.fn.has("win32") == 1 and 3 or 1
    if #args.dir > root_len and args.dir:sub(-1) == utils.path_separator then
      args.dir = args.dir:sub(1, -2)
    end

I added a comment as well just to clarify what was going on. Though, maybe it'd be better to have a constant. In utils, there's an is_windows variable set (which includes WSL). Maybe a root_len should be set here as well? I'm going to leave it at this for now, though.

@miversen33
Copy link
Collaborator

This works on my windows machine. It took me a bit to wrap my head around why it worked lol but ya it works :) @cseickel this should be good to merge.

@cseickel cseickel changed the base branch from v2.x to main June 11, 2023 00:38
@cseickel
Copy link
Contributor

This works on my windows machine. It took me a bit to wrap my head around why it worked lol but ya it works :) @cseickel this should be good to merge.

Thanks for checking @miversen33!

@cseickel cseickel merged commit 95776b6 into nvim-neo-tree:main Jun 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fails to list files when at the root of a drive on Windows
3 participants