@@ -81,6 +81,22 @@ local check_source = function(source_name)
8181 return source_name
8282end
8383
84+ local hijack_netrw = function ()
85+ local bufname = vim .api .nvim_buf_get_name (0 )
86+ local stats = vim .loop .fs_stat (bufname )
87+ local is_dir = stats and stats .type == " directory"
88+ if is_dir then
89+ local bufnr = vim .api .nvim_get_current_buf ()
90+ vim .cmd (" silent! b#" ) -- to make the alternate buffer correct after wiping the directory buffer
91+ manager .navigate (" filesystem" , bufname , nil , function ()
92+ vim .cmd (" bwipeout! " .. bufnr )
93+ end )
94+ return true
95+ else
96+ return false
97+ end
98+ end
99+
84100local get_position = function (source_name )
85101 local pos = utils .get_value (M , " config." .. source_name .. " .window.position" , " left" )
86102 return pos
@@ -154,19 +170,6 @@ M.focus = function(source_name, close_others, toggle_if_open)
154170 manager .focus (source_name )
155171end
156172
157- M .hijack_netrw = function ()
158- local bufname = vim .api .nvim_buf_get_name (0 )
159- local stats = vim .loop .fs_stat (bufname )
160- local is_dir = stats and stats .type == " directory"
161- if is_dir then
162- vim .cmd (" bwipeout!" )
163- manager .navigate (" filesystem" , bufname )
164- return true
165- else
166- return false
167- end
168- end
169-
170173M .reveal_current_file = function (source_name , toggle_if_open )
171174 source_name = check_source (source_name )
172175 if get_position (source_name ) == " split" then
@@ -280,7 +283,7 @@ M.buffer_enter_event = function(args)
280283 end
281284
282285 -- if vim is trying to open a dir, then we hijack it
283- if M . hijack_netrw () then
286+ if hijack_netrw () then
284287 return
285288 end
286289
0 commit comments