Skip to content

Commit dda4c9e

Browse files
authored
fix(mappings): fallback for focus_preview (#1738)
1 parent 2edd287 commit dda4c9e

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,14 @@ M.scroll_preview = function(state)
681681
Preview.scroll(state)
682682
end
683683

684-
M.focus_preview = function()
685-
Preview.focus()
684+
M.focus_preview = function(state)
685+
if Preview.is_active() then
686+
Preview.focus()
687+
else
688+
vim.api.nvim_win_call(state.winid, function()
689+
vim.api.nvim_feedkeys(state.fallback, "n", false)
690+
end)
691+
end
686692
end
687693

688694
---Expands or collapses the current node.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,8 @@ Preview.scroll = function(state)
506506
vim.cmd(("normal! %s%s"):format(count, input))
507507
end)
508508
else
509-
vim.api.nvim_buf_call(state.bufnr, function()
510-
vim.cmd(("normal! %s"):format(utils.keycode(state.fallback)))
509+
vim.api.nvim_win_call(state.winid, function()
510+
vim.api.nvim_feedkeys(state.fallback, "n", false)
511511
end)
512512
end
513513
end

lua/neo-tree/ui/renderer.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,9 +850,10 @@ local set_buffer_mappings = function(state)
850850
resolved_mappings[cmd] = { text = desc or "<function>" }
851851
end
852852
if type(func) == "function" then
853+
local fallback = utils.keycode(cmd)
853854
resolved_mappings[cmd].handler = function()
854855
state.config = config
855-
state.fallback = cmd
856+
state.fallback = fallback
856857
return func(state)
857858
end
858859
keymap.set(state.bufnr, "n", cmd, resolved_mappings[cmd].handler, map_options)

0 commit comments

Comments
 (0)