Skip to content

Commit

Permalink
Merge branch 'nvim-neo-tree:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
tribhuwan-kumar authored May 16, 2024
2 parents 582cc31 + 6e20108 commit 5d0c534
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions doc/neo-tree.txt
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ P = toggle_preview: Toggles "preview mode", see |neo-tree-preview-mode|

l = focus_preview: Focus the active preview window

<C-f> = scroll_preview: Scrolls preview window down (without focusing it)
see |neo-tree-preview-mode| for params

<C-b> = scroll_preview: Scrolls preview window up (without focusing it)
see |neo-tree-preview-mode| for params

<esc> = revert_preview: Ends "preview_mode" if it is enabled, and reverts
any preview windows to what was being shown before
preview mode began.
Expand Down Expand Up @@ -404,6 +410,9 @@ an existing split by configuring the command like this:
window = {
mappings = {
["P"] = { "toggle_preview", config = { use_float = false, use_image_nvim = true } },
["l"] = "focus_preview",
["<C-b>"] = { "scroll_preview", config = {direction = 10} },
["<C-f>"] = { "scroll_preview", config = {direction = -10} },
}
}
})
Expand Down
2 changes: 2 additions & 0 deletions lua/neo-tree/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ local config = {
-- ["<cr>"] = { "open", config = { expand_nested_files = true } }, -- expand nested file takes precedence
["<esc>"] = "cancel", -- close preview or floating neo-tree window
["P"] = { "toggle_preview", config = { use_float = true, use_image_nvim = false } },
["<C-f>"] = { "scroll_preview", config = {direction = -10} },
["<C-b>"] = { "scroll_preview", config = {direction = 10} },
["l"] = "focus_preview",
["S"] = "open_split",
-- ["S"] = "split_with_window_picker",
Expand Down
4 changes: 4 additions & 0 deletions lua/neo-tree/sources/common/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,10 @@ M.toggle_preview = function(state)
Preview.toggle(state)
end

M.scroll_preview = function(state)
Preview.scroll(state)
end

M.focus_preview = function()
Preview.focus()
end
Expand Down
14 changes: 14 additions & 0 deletions lua/neo-tree/sources/common/preview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -435,4 +435,18 @@ Preview.focus = function()
end
end

Preview.scroll = function(state)
local direction = state.config.direction
-- NOTE: Chars below are raw escape codes for <Ctrl-E>/<Ctrl-Y>
local input = direction < 0 and [[]] or [[]]
local count = math.abs(direction)

if Preview:is_active() then
vim.api.nvim_win_call(instance.winid, function()
vim.cmd([[normal! ]] .. count .. input)
end)
end

end

return Preview

0 comments on commit 5d0c534

Please sign in to comment.