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 62
62
63
63
M .paste_default_config = function ()
64
64
local utils = require (" neo-tree.utils" )
65
- --- @type string
66
65
local base_path = assert (debug.getinfo (utils .truthy ).source :match (" @(.*)/utils/init.lua$" ))
67
- --- @type string
68
66
local config_path = base_path .. utils .path_separator .. " defaults.lua"
69
- --- @type string[] ?
70
67
local lines = vim .fn .readfile (config_path )
71
68
if lines == nil then
72
69
error (" Could not read neo-tree.defaults" )
Original file line number Diff line number Diff line change 101
101
--- @param path string
102
102
--- @param validate_type string ?
103
103
M .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 )
107
105
if validate_type then
108
106
local stat = uv .fs_stat (abs_path )
109
107
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)
230
230
end
231
231
end
232
232
233
+ --- Get the path to reveal in the file tree.
234
+ --- @param include_terminals boolean ?
235
+ --- @return string ? path
233
236
M .get_path_to_reveal = function (include_terminals )
234
237
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
237
239
-- floating window, ignore
238
240
return nil
239
241
end
242
+
240
243
if vim .bo .filetype == " neo-tree" then
241
244
return nil
242
245
end
243
- local path = vim .fn .expand (" %:p" )
246
+
247
+ local path = utils .resolve_path (vim .api .nvim_buf_get_name (0 ))
244
248
if not utils .truthy (path ) then
245
249
return nil
246
250
end
Original file line number Diff line number Diff line change @@ -1075,6 +1075,40 @@ M.path_join = function(...)
1075
1075
return table.concat (all_parts , M .path_separator )
1076
1076
end
1077
1077
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
+
1078
1112
local table_merge_internal
1079
1113
--- Merges overrideTable into baseTable. This mutates baseTable.
1080
1114
--- @param base_table table The base table that provides default values.
You can’t perform that action at this time.
0 commit comments