Skip to content

Commit 5d8b1be

Browse files
authored
feat: support nvim 0.11 winborder as popup.border (#163)
* feat: use global nvim option 'winborder' as popup border default * feat: use 'winborder' only on nvim versions >= 0.11.0 * refactor(popup): Rewrite `popup.border` handling and set the default config value to `nil`. Provide a utility function that resolves the actual border value depending on the config value and `neovim` version. * docs: Regenerate documentation for `popup.border`
1 parent fc59684 commit 5d8b1be

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

doc/crates.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ For more information about individual config options see |crates-config|.
118118
hide_on_select = false,
119119
copy_register = '"',
120120
style = "minimal",
121-
border = "none",
121+
border = nil,
122122
show_version_date = false,
123123
show_dependency_version = true,
124124
max_height = 30,
@@ -822,10 +822,13 @@ popup.style *crates-config-popup-style*
822822

823823

824824
popup.border *crates-config-popup-border*
825-
Type: `string|string[]`, Default: `"none"`
825+
Type: `string|string[]`, Default: `nil`
826826

827827
Same as nvim_open_win config.border.
828828

829+
If unset or nil, defaults to global 'winborder' on nvim >= 0.11.0, else
830+
"none".
831+
829832

830833
popup.show_version_date *crates-config-popup-show_version_date*
831834
Type: `boolean`, Default: `false`

docgen/wiki/Documentation-unstable.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ require("crates").setup {
276276
hide_on_select = false,
277277
copy_register = '"',
278278
style = "minimal",
279-
border = "none",
279+
border = nil,
280280
show_version_date = false,
281281
show_dependency_version = true,
282282
max_height = 30,

lua/crates/config/init.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,9 +598,12 @@ entry(schema_popup, {
598598
config_type = { "string", "table" },
599599
emmylua_annotation = "string|string[]",
600600
},
601-
default = "none",
601+
default = nil,
602602
description = [[
603603
Same as nvim_open_win config.border.
604+
605+
If unset or nil, defaults to global 'winborder' on nvim >= 0.11.0, else
606+
"none".
604607
]],
605608
})
606609
entry(schema_popup, {

lua/crates/popup/common.lua

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,22 @@ function M.update_win(width, height, title, text, opts)
165165
vim.api.nvim_win_set_cursor(M.win, { l, 0 })
166166
end
167167

168+
--- Get the border of the popup menu.
169+
---
170+
--- Returns the first valid value out of the following choices (in that order):
171+
--- 1. Config value `popup.border`, if configured
172+
--- 2. Global `winborder`, if neovim version >= 0.11.0
173+
--- 3. `"none"`
174+
local function popup_border()
175+
if state.cfg.popup.border ~= nil then
176+
return state.cfg.popup.border
177+
elseif vim.version.ge(vim.version(), {0, 11, 0}) then
178+
return vim.opt_global.winborder:get()
179+
else
180+
return "none"
181+
end
182+
end
183+
168184
---@param width integer
169185
---@param height integer
170186
---@param title string
@@ -185,7 +201,7 @@ function M.open_win(width, height, title, text, opts, configure)
185201
width = width,
186202
height = height,
187203
style = state.cfg.popup.style,
188-
border = state.cfg.popup.border,
204+
border = popup_border(),
189205
})
190206

191207
-- add key mappings

0 commit comments

Comments
 (0)