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

Feature: allow to configure window options as functions #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion doc/navbuddy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Use |navbuddy.setup| to override any of the default options
have nerd-fonts.

window: table
Set options related to window's "border", "size", "position".
Set options related to window's "border", "relative", "size", "position".

node_markers: table
Indicate whether a node is a leaf or branch node. Default icons assume
Expand Down Expand Up @@ -112,8 +112,16 @@ Defaults >lua
border = "single", -- "rounded", "double", "solid", "none"
-- or an array with eight chars building up the border in a clockwise fashion
-- starting with the top-left corner. eg: { "╔", "═" ,"╗", "║", "╝", "═", "╚", "║" }.

relative = "editor" -- "editor", "cursor", "win", "buf"
-- or a function returning a relative value or table (current window as parameter)

size = "60%", -- Or table format example: { height = "40%", width = "100%"}
-- or a function returning a size value or table (current window as parameter)

position = "50%", -- Or table format example: { row = "100%", col = "0%"}
-- or a function returning a position value or table (current window as parameter)

scrolloff = nil, -- scrolloff value within navbuddy window
sections = {
left = {
Expand Down
15 changes: 12 additions & 3 deletions lua/nvim-navbuddy/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -650,12 +650,21 @@ function actions.help()
local callback = function(display)
display:close()

local relative = display.config.window.relative
relative = type(relative) == "function" and relative(display.for_win) or relative

local position = display.config.window.position
position = type(position) == "function" and position(display.for_win) or position

local size = display.config.window.size
size = type(size) == "function" and size(display.for_win) or size

local nui_popup = require("nui.popup")

local help_popup = nui_popup({
relative = "editor",
position = display.config.window.position,
size = display.config.window.size,
relative = relative,
position = position,
size = size,
enter = true,
focusable = true,
border = display.config.window.border,
Expand Down
15 changes: 12 additions & 3 deletions lua/nvim-navbuddy/display.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,20 @@ function display:new(obj)
},
})

local relative = config.window.relative
relative = type(relative) == "function" and relative(obj.for_win) or relative

local position = config.window.position
position = type(position) == "function" and position(obj.for_win) or position

local size = config.window.size
size = type(size) == "function" and size(obj.for_win) or size

local layout = nui_layout(
{
relative = "editor",
position = config.window.position,
size = config.window.size,
relative = relative,
position = position,
size = size,
},
nui_layout.Box({
nui_layout.Box(left_popup, { size = config.window.sections.left.size }),
Expand Down
1 change: 1 addition & 0 deletions lua/nvim-navbuddy/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local actions = require("nvim-navbuddy.actions")
local config = {
window = {
border = "single",
relative = "editor",
size = "60%",
position = "50%",
scrolloff = nil,
Expand Down