Skip to content

Commit 03ac32a

Browse files
authored
fix(border): Failing to display if row negative (#240)
This commit aims to fix an issue with the Border component, which makes it impossible to draw the top and bottom lines and makes the middle line replace the former, if the row is a negative value. The issues stems from an if condition which prevents top line from being created, if the row has a negative or 0 value. This also makes it impossible to use the `plenary.popup` cursor-relative positioning, as a value such as 'cursor-2' would break the popup. It makes it so the if statement conditioning the rendering of a topline takes into account the boundaries of the current window, whether the position is absolute or cursor-relative. It also removes the top thickness of the hidden border, as pointed out by @l-kershaw. Finally, this commit ensures that cursor-relative position takes into account the editor-relative position of the cursor, not only the window one, as it lead to problems when not setting a certain `showtabline`. It also created an undesired behaviour of "pushing" the popup down, in order to make room for the topline.
1 parent edb76cc commit 03ac32a

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

lua/plenary/window/border.lua

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,17 @@ function Border._create_lines(content_win_options, border_win_options)
7373
or border_win_options.title
7474
or {}
7575

76-
if content_win_options.row > 0 then
76+
--[[
77+
-- Ensure that the topline is drawn only if the row is positive (for an absolute position) or if when added to the current
78+
-- cursor line (for a cursor relative position) it is also a positive value.
79+
--]]
80+
if
81+
content_win_options.row > 0
82+
or (
83+
content_win_options.relative == "cursor"
84+
and content_win_options.row + vim.api.nvim_win_get_cursor(0)[1] + vim.api.nvim_win_get_position(0)[1] > 1
85+
)
86+
then
7787
for _, title in ipairs(titles) do
7888
if string.find(title.pos, "N") then
7989
topline = create_horizontal_line(
@@ -92,6 +102,8 @@ function Border._create_lines(content_win_options, border_win_options)
92102
topline = topleft .. string.rep(border_win_options.top, content_win_options.width) .. topright
93103
end
94104
end
105+
else
106+
border_win_options.border_thickness.top = 0
95107
end
96108

97109
if topline then

0 commit comments

Comments
 (0)