@@ -98,7 +98,7 @@ local instance = nil
9898function Preview :new (state )
9999 local preview = {}
100100 preview .active = false
101- preview .config = state .config
101+ preview .config = vim . deepcopy ( state .config )
102102 setmetatable (preview , { __index = self })
103103 preview :findWindow (state )
104104 return preview
207207--- Finds the appropriate window and updates the preview accordingly.
208208--- @param state table The state of the source.
209209function Preview :findWindow (state )
210- self .config = state .config
211210 local winid , is_neo_tree_window
212211 if self .config .use_float then
213212 if
@@ -337,7 +336,10 @@ function Preview:clearHighlight()
337336 end
338337end
339338
339+ local toggle_state = false
340+
340341Preview .hide = function ()
342+ toggle_state = false
341343 if instance then
342344 instance :revert ()
343345 end
@@ -352,11 +354,6 @@ Preview.show = function(state)
352354
353355 if instance then
354356 instance :findWindow (state )
355- if not renderer .is_window_valid (instance .winid ) then
356- log .warn (" Preview window is not valid" )
357- Preview .hide ()
358- instance = Preview :new (state )
359- end
360357 else
361358 instance = Preview :new (state )
362359 end
@@ -373,17 +370,23 @@ Preview.show = function(state)
373370end
374371
375372Preview .toggle = function (state )
376- if instance then
373+ if toggle_state then
377374 Preview .hide ()
378375 else
376+ toggle_state = true
379377 Preview .show (state )
378+ local winid = state .winid
379+ local source_name = state .name
380380 local preview_event = {
381381 event = events .VIM_CURSOR_MOVED ,
382382 handler = function ()
383- if not instance .active then
383+ log .debug (" Cursor moved, updating preview" )
384+ if not toggle_state then
385+ log .warn (" Preview is not active, not updating" )
384386 return
385387 end
386- if vim .api .nvim_get_current_win () == state .winid then
388+ if vim .api .nvim_get_current_win () == winid then
389+ log .debug (" Cursor moved in tree window, updating preview" )
387390 Preview .show (state )
388391 else
389392 log .debug (" Neo-tree window lost focus, disposing preview" )
@@ -392,7 +395,7 @@ Preview.toggle = function(state)
392395 end ,
393396 id = " preview-event" ,
394397 }
395- instance :subscribe (state . name , preview_event )
398+ instance :subscribe (source_name , preview_event )
396399 end
397400end
398401
0 commit comments