Skip to content

Comments

fix(files): properly normalize root directory on Windows#2277

Closed
TheLeoP wants to merge 1 commit intonvim-mini:mainfrom
TheLeoP:fix_win
Closed

fix(files): properly normalize root directory on Windows#2277
TheLeoP wants to merge 1 commit intonvim-mini:mainfrom
TheLeoP:fix_win

Conversation

@TheLeoP
Copy link
Member

@TheLeoP TheLeoP commented Feb 19, 2026

Fixes the issue described in #2272 based on the findings of #2272 (comment)

@TheLeoP
Copy link
Member Author

TheLeoP commented Feb 19, 2026

Actually, after this PR, simply hovering one of C://pagefile.sys, C://swapfile.sys or C://DumpStack.log.tmp and then moving the cursor on top of any other file on the C:/ directory will result in a similar error to the one described in #2272 with the same minimal reproduction

    require("mini.files").setup {
      windows = {
        preview = true,
      },
    }
    vim.api.nvim_create_autocmd("User", {
      pattern = "MiniFilesWindowUpdate",
      callback = function()
        local s = MiniFiles.get_explorer_state()
      end,
    })

@TheLeoP
Copy link
Member Author

TheLeoP commented Feb 20, 2026

This PR already handles the most common case of root directory normalization in Windows, but after a few iterations I ended up with

if H.is_windows then
  H.fs_normalize_path = function(path)
    path = path:gsub('\\', '/')
    local head, tail = path:match('^(%w:/+)(.*)$')
    -- preserve number of slashes if 1 or 2, normalize more than 2 slashes to 1
    if #head > 4 then head = head:gsub('/+', '/') end
    tail = tail:gsub('(.)/$', '%1')
    return head .. tail
  end
end

instead that also handles the aforementioned special paths that require specifically C:// instead of just C:/, but I'm not sure if complicating the normalization logic even more is worth it for such a niche case. It's your call @echasnovski

@nickvonkaenel
Copy link
Contributor

This fix results in an error for me when using MiniFiles.reveal_cwd(). Please see the fix in my PR.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants