Skip to content

Commit

Permalink
feat(preview): custom title (#1563)
Browse files Browse the repository at this point in the history
Co-authored-by: pynappo <lehtien.david@gmail.com>
  • Loading branch information
joaomendoncaa and pynappo authored Jan 18, 2025
1 parent 83222b3 commit 891e3af
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,14 @@ an existing split by configuring the command like this:
require("neo-tree").setup({
window = {
mappings = {
["P"] = { "toggle_preview", config = { use_float = false, use_image_nvim = true } },
["P"] = {
"toggle_preview",
config = {
use_float = false,
-- use_image_nvim = true,
-- title = 'Neo-tree Preview',
},
},
}
}
})
Expand All @@ -739,6 +746,8 @@ Anything that causes Neo-tree to lose focus will end preview mode. When
`use_float = false`, the window that was taken over by preview mode will revert
back to whatever was shown in that window before preview mode began.

You can choose a custom title for the floating window by setting the `title` option in its config.

If you want to work with the floating preview mode window in autocmds or other
custom code, the window will have the `neo-tree-preview` filetype.

Expand Down
6 changes: 5 additions & 1 deletion lua/neo-tree/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,11 @@ local config = {
["<cr>"] = "open",
-- ["<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 } },
["P"] = { "toggle_preview", config = {
use_float = true,
use_image_nvim = false,
-- title = "Neo-tree Preview", -- You can define a custom title for the preview floating window.
} },
["<C-f>"] = { "scroll_preview", config = {direction = -10} },
["<C-b>"] = { "scroll_preview", config = {direction = 10} },
["l"] = "focus_preview",
Expand Down
4 changes: 2 additions & 2 deletions lua/neo-tree/sources/common/preview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ local function create_floating_preview_window(state)
local default_position = utils.resolve_config_option(state, "window.position", "left")
state.current_position = state.current_position or default_position

local title = state.config.title or "Neo-tree Preview"
local winwidth = vim.api.nvim_win_get_width(state.winid)
local winheight = vim.api.nvim_win_get_height(state.winid)
local height = vim.o.lines - 4
Expand Down Expand Up @@ -58,7 +59,7 @@ local function create_floating_preview_window(state)
end

local popups = require("neo-tree.ui.popups")
local options = popups.popup_options("Neo-tree Preview", width, {
local options = popups.popup_options(title, width, {
ns_id = highlights.ns_id,
size = { height = height, width = width },
relative = "editor",
Expand Down Expand Up @@ -446,7 +447,6 @@ Preview.scroll = function(state)
vim.cmd([[normal! ]] .. count .. input)
end)
end

end

return Preview

0 comments on commit 891e3af

Please sign in to comment.