Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(preview): custom title #1563

Merged
merged 3 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,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 @@ -724,6 +731,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 @@ -378,7 +378,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