@@ -136,16 +136,16 @@ M.close = function(state, focus_prior_window)
136
136
end
137
137
vim .api .nvim_win_set_buf (state .winid , new_buf )
138
138
else
139
+ local args = {
140
+ position = state .current_position ,
141
+ source = state .name ,
142
+ winid = state .winid ,
143
+ tabnr = tabid_to_tabnr (state .tabid ), -- for compatibility
144
+ tabid = state .tabid ,
145
+ }
139
146
events .fire_event (events .NEO_TREE_WINDOW_BEFORE_CLOSE , args )
140
147
local win_list = vim .api .nvim_tabpage_list_wins (0 )
141
148
if focus_prior_window and # win_list > 1 then
142
- local args = {
143
- position = state .current_position ,
144
- source = state .name ,
145
- winid = state .winid ,
146
- tabnr = tabid_to_tabnr (state .tabid ), -- for compatibility
147
- tabid = state .tabid ,
148
- }
149
149
-- focus the prior used window if we are closing the currently focused window
150
150
local current_winid = vim .api .nvim_get_current_win ()
151
151
if current_winid == state .winid then
@@ -163,14 +163,15 @@ M.close = function(state, focus_prior_window)
163
163
end
164
164
state .winid = nil
165
165
end
166
- if window_existed then
167
- local bufnr = utils . get_value ( state , " bufnr" , 0 , true )
166
+ local bufnr = utils . get_value ( state , " bufnr " , 0 , true )
167
+ if bufnr > 0 and vim . api . nvim_buf_is_valid ( bufnr ) then
168
168
state .bufnr = nil
169
- vim .schedule (function ()
170
- if bufnr > 0 and vim .api .nvim_buf_is_valid (bufnr ) then
169
+ local success , err = pcall (vim .api .nvim_buf_delete , bufnr , { force = true })
170
+ if not success and err and err :match (" E523" ) then
171
+ vim .schedule_wrap (function ()
171
172
vim .api .nvim_buf_delete (bufnr , { force = true })
172
- end
173
- end )
173
+ end )()
174
+ end
174
175
end
175
176
return window_existed
176
177
end
0 commit comments