109109--- @param start_pos table ? The (0-indexed ) starting position of the previewed text. May be absent.
110110--- @param end_pos table ? The (0-indexed ) ending position of the previewed text. May be absent
111111function Preview :preview (bufnr , start_pos , end_pos )
112- log .warn (" Creating preview window" )
113112 if self .is_neo_tree_window then
114- log .error (" Could not find appropriate window for preview" )
113+ log .warn (" Could not find appropriate window for preview" )
115114 return
116115 end
117116
@@ -121,7 +120,6 @@ function Preview:preview(bufnr, start_pos, end_pos)
121120 end
122121
123122 if not self .active then
124- log .warn (" Could not activate preview window." )
125123 return
126124 end
127125
194192
195193--- Unsubscribe to all events in the preview event list.
196194function Preview :unsubscribe ()
195+ if self .events == nil then
196+ return
197+ end
197198 for _ , event in ipairs (self .events ) do
198199 if event .source == nil then
199200 events .unsubscribe (event .event )
@@ -216,7 +217,6 @@ function Preview:findWindow(state)
216217 then
217218 return
218219 end
219- local renderer = require (" neo-tree.ui.renderer" )
220220 local win = create_floating_preview_window (state )
221221 if not win then
222222 self .active = false
@@ -373,16 +373,19 @@ Preview.toggle = function(state)
373373 if toggle_state then
374374 Preview .hide ()
375375 else
376- toggle_state = true
377376 Preview .show (state )
377+ if instance and instance .active then
378+ toggle_state = true
379+ else
380+ Preview .hide ()
381+ return
382+ end
378383 local winid = state .winid
379384 local source_name = state .name
380385 local preview_event = {
381386 event = events .VIM_CURSOR_MOVED ,
382387 handler = function ()
383- log .debug (" Cursor moved, updating preview" )
384388 if not toggle_state then
385- log .warn (" Preview is not active, not updating" )
386389 return
387390 end
388391 if vim .api .nvim_get_current_win () == winid then
0 commit comments