File tree Expand file tree Collapse file tree 4 files changed +42
-9
lines changed Expand file tree Collapse file tree 4 files changed +42
-9
lines changed Original file line number Diff line number Diff line change 6262
6363M .paste_default_config = function ()
6464 local utils = require (" neo-tree.utils" )
65- --- @type string
6665 local base_path = assert (debug.getinfo (utils .truthy ).source :match (" @(.*)/utils/init.lua$" ))
67- --- @type string
6866 local config_path = base_path .. utils .path_separator .. " defaults.lua"
69- --- @type string[] ?
7067 local lines = vim .fn .readfile (config_path )
7168 if lines == nil then
7269 error (" Could not read neo-tree.defaults" )
Original file line number Diff line number Diff line change 101101--- @param path string
102102--- @param validate_type string ?
103103M .resolve_path = function (path , validate_type )
104- path = vim .fs .normalize (path )
105- local expanded = vim .fn .expand (path )
106- local abs_path = vim .fn .fnamemodify (expanded , " :p" )
104+ local abs_path = utils .resolve_path (path )
107105 if validate_type then
108106 local stat = uv .fs_stat (abs_path )
109107 if not stat or stat .type ~= validate_type then
Original file line number Diff line number Diff line change @@ -230,17 +230,21 @@ M.get_state_for_window = function(winid)
230230 end
231231end
232232
233+ --- Get the path to reveal in the file tree.
234+ --- @param include_terminals boolean ?
235+ --- @return string ? path
233236M .get_path_to_reveal = function (include_terminals )
234237 local win_id = vim .api .nvim_get_current_win ()
235- local cfg = vim .api .nvim_win_get_config (win_id )
236- if cfg .relative > " " or cfg .external then
238+ if utils .is_floating (win_id ) then
237239 -- floating window, ignore
238240 return nil
239241 end
242+
240243 if vim .bo .filetype == " neo-tree" then
241244 return nil
242245 end
243- local path = vim .fn .expand (" %:p" )
246+
247+ local path = utils .resolve_path (vim .api .nvim_buf_get_name (0 ))
244248 if not utils .truthy (path ) then
245249 return nil
246250 end
Original file line number Diff line number Diff line change @@ -1075,6 +1075,40 @@ M.path_join = function(...)
10751075 return table.concat (all_parts , M .path_separator )
10761076end
10771077
1078+ --- @param path string
1079+ M .is_absolute_path = function (path )
1080+ if M .is_windows then
1081+ -- Check for Windows absolute paths
1082+ -- Drive letter followed by colon and a slash (e.g., C:\ or C:/)
1083+ if path :match (" ^[A-Za-z]:[/\\ ]" ) then
1084+ return true
1085+ end
1086+ -- UNC paths (network paths)
1087+ if path :sub (1 , 2 ) == " \\\\ " or path :sub (1 , 2 ) == " //" then
1088+ return true
1089+ end
1090+ -- Windows absolute path starting with a single backslash (relative to current drive root)
1091+ if path :sub (1 , 1 ) == " \\ " then
1092+ return true
1093+ end
1094+ else
1095+ return path :sub (1 , 1 ) == " /"
1096+ end
1097+
1098+ return false
1099+ end
1100+
1101+ --- Resolve a path relative to the cwd
1102+ --- @param path string
1103+ --- @return string path
1104+ M .resolve_path = function (path )
1105+ local expanded = vim .fn .expand (path )
1106+ if not M .is_absolute_path (expanded ) then
1107+ expanded = vim .fn .getcwd () .. " /" .. expanded
1108+ end
1109+ return M .normalize_path (expanded )
1110+ end
1111+
10781112local table_merge_internal
10791113--- Merges overrideTable into baseTable. This mutates baseTable.
10801114--- @param base_table table The base table that provides default values.
You can’t perform that action at this time.
0 commit comments