Skip to content

Commit 35e9f9b

Browse files
committed
fix(preview): fail gracefully when preview toggle attempted when position=current
1 parent 5741fda commit 35e9f9b

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

lua/neo-tree/sources/common/preview.lua

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,8 @@ end
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
111111
function 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

@@ -194,6 +192,9 @@ end
194192

195193
---Unsubscribe to all events in the preview event list.
196194
function 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

lua/neo-tree/ui/renderer.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ M.close = function(state)
7474
local window_existed = false
7575
if state and state.winid then
7676
if M.window_exists(state) then
77-
Preview.dispose(state)
7877
local bufnr = vim.api.nvim_win_get_buf(state.winid)
7978
-- if bufnr is different then we expect, then it was taken over by
8079
-- another buffer, so we can't delete it now

0 commit comments

Comments
 (0)