Skip to content

Commit d8b8c83

Browse files
authored
feat: add focus_preview command, closes #672 (#675)
1 parent d9e50c1 commit d8b8c83

File tree

5 files changed

+15
-1
lines changed

5 files changed

+15
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ use {
200200
["<cr>"] = "open",
201201
["<esc>"] = "revert_preview",
202202
["P"] = { "toggle_preview", config = { use_float = true } },
203+
["l"] = "focus_preview"
203204
["S"] = "open_split",
204205
["s"] = "open_vsplit",
205206
-- ["S"] = "split_with_window_picker",

doc/neo-tree.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ z = close_all_nodes: Close all nodes in the tree.
195195

196196
P = toggle_preview: Toggles "preview mode", see |neo-tree-preview-mode|
197197

198+
l = focus_preview: Focus the active preview window
199+
198200
<esc> = revert_preview: Ends "preview_mode" if it is enabled, and reverts
199201
any preview windows to what was being shown before
200202
preview mode began.

lua/neo-tree/defaults.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ local config = {
312312
["<cr>"] = "open",
313313
["<esc>"] = "revert_preview",
314314
["P"] = { "toggle_preview", config = { use_float = true } },
315+
["l"] = "focus_preview",
315316
["S"] = "open_split",
316317
-- ["S"] = "split_with_window_picker",
317318
["s"] = "open_vsplit",

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,10 @@ M.toggle_preview = function(state)
487487
Preview.toggle(state)
488488
end
489489

490+
M.focus_preview = function()
491+
Preview.focus()
492+
end
493+
490494
---Open file or directory
491495
---@param state table The state of the source
492496
---@param open_cmd string The vim command to use to open the file

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ Preview.toggle = function(state)
393393
local preview_event = {
394394
event = events.VIM_CURSOR_MOVED,
395395
handler = function()
396-
if not toggle_state then
396+
if not toggle_state or vim.api.nvim_get_current_win() == instance.winid then
397397
return
398398
end
399399
if vim.api.nvim_get_current_win() == winid then
@@ -410,4 +410,10 @@ Preview.toggle = function(state)
410410
end
411411
end
412412

413+
Preview.focus = function()
414+
if Preview.is_active() then
415+
vim.fn.win_gotoid(instance.winid)
416+
end
417+
end
418+
413419
return Preview

0 commit comments

Comments
 (0)