Skip to content

Commit da59247

Browse files
authored
Fixed some trailing slash bugs (#957)
* Fixed issue where user would have to trigger dir-up action multiple times to get it to work * Fix to path_join to ensure the result does not have a double slash
1 parent b54de4b commit da59247

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

lua/nvim-tree/actions/change-dir.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local a = vim.api
22
local lib = function() return require'nvim-tree.lib' end
3+
local utils = require'nvim-tree.utils'
34

45
local M = {
56
current_tab = a.nvim_get_current_tabpage(),
@@ -9,7 +10,7 @@ local M = {
910
}
1011

1112
function M.fn(name)
12-
local foldername = name == '..' and vim.fn.fnamemodify(TreeExplorer.cwd, ':h') or name
13+
local foldername = name == '..' and vim.fn.fnamemodify(utils.path_remove_trailing(TreeExplorer.cwd), ':h') or name
1314
local no_cwd_change = vim.fn.expand(foldername) == TreeExplorer.cwd
1415
local new_tab = a.nvim_get_current_tabpage()
1516
local is_window = vim.v.event.scope == "window" and new_tab == M.current_tab

lua/nvim-tree/actions/dir-up.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
local utils = require'nvim-tree.utils'
2+
13
local M = {}
24

35
function M.fn(node)
46
if not node or node.name == ".." then
57
return require'nvim-tree.actions.change-dir'.fn('..')
68
else
7-
local newdir = vim.fn.fnamemodify(TreeExplorer.cwd, ':h')
9+
local newdir = vim.fn.fnamemodify(utils.path_remove_trailing(TreeExplorer.cwd), ':h')
810
require'nvim-tree.actions.change-dir'.fn(newdir)
911
return require"nvim-tree.actions.find-file".fn(node.absolute_path)
1012
end

lua/nvim-tree/utils.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ end
2929

3030
local path_separator = package.config:sub(1,1)
3131
function M.path_join(paths)
32-
return table.concat(paths, path_separator)
32+
return table.concat(vim.tbl_map(M.path_remove_trailing, paths), path_separator)
3333
end
3434

3535
function M.path_split(path)

0 commit comments

Comments
 (0)