@@ -43,33 +43,37 @@ M.hijack = function()
43
43
end
44
44
45
45
-- record where we are now
46
- local should_open_current = hijack_behavior == " open_current" or get_position (" filesystem" ) == " current"
46
+ local pos = get_position (" filesystem" )
47
+ local should_open_current = hijack_behavior == " open_current" or pos == " current"
47
48
local winid = vim .api .nvim_get_current_win ()
48
49
local dir_bufnr = vim .api .nvim_get_current_buf ()
49
50
50
- -- We will want to replace the "directory" buffer with either the "alternate"
51
- -- buffer or a new blank one.
52
- local replace_with_bufnr = vim .fn .bufnr (" #" )
53
- if replace_with_bufnr > 0 then
54
- if vim .api .nvim_buf_get_option (replace_with_bufnr , " filetype" ) == " neo-tree" then
55
- replace_with_bufnr = - 1
56
- end
57
- end
58
- if not should_open_current then
59
- if replace_with_bufnr == dir_bufnr or replace_with_bufnr < 1 then
60
- replace_with_bufnr = vim .api .nvim_create_buf (true , false )
61
- end
62
- end
63
- if replace_with_bufnr > 0 then
64
- pcall (vim .api .nvim_win_set_buf , winid , replace_with_bufnr )
65
- end
66
- local remove_dir_buf = vim .schedule_wrap (function ()
67
- pcall (vim .api .nvim_buf_delete , dir_bufnr , { force = true })
68
- end )
69
-
70
51
-- Now actually open the tree, with a very quick debounce because this may be
71
52
-- called multiple times in quick succession.
72
53
utils .debounce (" hijack_netrw_" .. winid , function ()
54
+ -- We will want to replace the "directory" buffer with either the "alternate"
55
+ -- buffer or a new blank one.
56
+ local replace_with_bufnr = vim .fn .bufnr (" #" )
57
+ if replace_with_bufnr > 0 then
58
+ if vim .api .nvim_buf_get_option (replace_with_bufnr , " filetype" ) == " neo-tree" then
59
+ replace_with_bufnr = - 1
60
+ end
61
+ end
62
+ if not should_open_current then
63
+ if replace_with_bufnr == dir_bufnr or replace_with_bufnr < 1 then
64
+ replace_with_bufnr = vim .api .nvim_create_buf (true , false )
65
+ log .trace (" Created new buffer for netrw hijack" , replace_with_bufnr )
66
+ end
67
+ end
68
+ if replace_with_bufnr > 0 then
69
+ log .trace (" Replacing buffer in netrw hijack" , replace_with_bufnr )
70
+ pcall (vim .api .nvim_win_set_buf , winid , replace_with_bufnr )
71
+ end
72
+ local remove_dir_buf = vim .schedule_wrap (function ()
73
+ log .trace (" Deleting buffer in netrw hijack" , dir_bufnr )
74
+ pcall (vim .api .nvim_buf_delete , dir_bufnr , { force = true })
75
+ end )
76
+
73
77
local state
74
78
if should_open_current then
75
79
log .debug (" hijack_netrw: opening current" )
0 commit comments