@@ -55,41 +55,37 @@ local create_horizontal_line = function(title, pos, width, left_char, mid_char,
55
55
return horizontal_line , ranges
56
56
end
57
57
58
- function Border ._create_lines (content_win_options , border_win_options )
58
+ function Border ._create_lines (content_win_id , content_win_options , border_win_options )
59
+ local content_pos = vim .api .nvim_win_get_position (content_win_id )
60
+ local content_height = vim .api .nvim_win_get_height (content_win_id )
61
+ local content_width = vim .api .nvim_win_get_width (content_win_id )
62
+
59
63
-- TODO: Handle border width, which I haven't right here.
60
64
local thickness = border_win_options .border_thickness
61
65
62
66
local top_enabled = thickness .top == 1
63
- local right_enabled = thickness .right == 1
67
+ local right_enabled = thickness .right == 1 and content_pos [ 2 ] + content_width < vim . o . columns
64
68
local bot_enabled = thickness .bot == 1
65
- local left_enabled = thickness .left == 1
69
+ local left_enabled = thickness .left == 1 and content_pos [2 ] > 0
70
+
71
+ border_win_options .border_thickness .left = left_enabled and 1 or 0
72
+ border_win_options .border_thickness .right = right_enabled and 1 or 0
66
73
67
74
local border_lines = {}
68
75
local ranges = {}
69
76
70
- local topline = nil
71
-
72
- local topleft = (left_enabled and border_win_options .topleft ) or " "
73
- local topright = (right_enabled and border_win_options .topright ) or " "
74
-
75
77
-- border_win_options.title should have be a list with entries of the
76
78
-- form: { pos = foo, text = bar }.
77
79
-- pos can take values in { "NW", "N", "NE", "SW", "S", "SE" }
78
80
local titles = type (border_win_options .title ) == " string" and { { pos = " N" , text = border_win_options .title } }
79
81
or border_win_options .title
80
82
or {}
81
83
82
- --[[
83
- -- Ensure that the topline is drawn only if the row is positive (for an absolute position) or if when added to the current
84
- -- cursor line (for a cursor relative position) it is also a positive value.
85
- --]]
86
- if
87
- content_win_options .row > 0
88
- or (
89
- content_win_options .relative == " cursor"
90
- and content_win_options .row + vim .api .nvim_win_get_cursor (0 )[1 ] + vim .api .nvim_win_get_position (0 )[1 ] > 1
91
- )
92
- then
84
+ local topline = nil
85
+ local topleft = (left_enabled and border_win_options .topleft ) or " "
86
+ local topright = (right_enabled and border_win_options .topright ) or " "
87
+ -- Only calculate the topline if there is space above the first content row (relative to the editor)
88
+ if content_pos [1 ] > 0 then
93
89
for _ , title in ipairs (titles ) do
94
90
if string.find (title .pos , " N" ) then
95
91
local top_ranges
@@ -131,10 +127,10 @@ function Border._create_lines(content_win_options, border_win_options)
131
127
table.insert (border_lines , middle_line )
132
128
end
133
129
134
- if bot_enabled then
135
- local botline = nil
136
- local botleft = (left_enabled and border_win_options .botleft ) or " "
137
- local botright = ( right_enabled and border_win_options . botright ) or " "
130
+ local botline = nil
131
+ local botleft = ( left_enabled and border_win_options . botleft ) or " "
132
+ local botright = (right_enabled and border_win_options .botright ) or " "
133
+ if content_pos [ 1 ] + content_height < vim . o . lines then
138
134
for _ , title in ipairs (titles ) do
139
135
if string.find (title .pos , " S" ) then
140
136
local bot_ranges
@@ -153,10 +149,15 @@ function Border._create_lines(content_win_options, border_win_options)
153
149
end
154
150
end
155
151
if botline == nil then
156
- if top_enabled then
152
+ if bot_enabled then
157
153
botline = botleft .. string.rep (border_win_options .bot , content_win_options .width ) .. botright
158
154
end
159
155
end
156
+ else
157
+ border_win_options .border_thickness .bot = 0
158
+ end
159
+
160
+ if botline then
160
161
table.insert (border_lines , botline )
161
162
end
162
163
@@ -178,7 +179,11 @@ function Border:change_title(new_title)
178
179
end
179
180
180
181
self ._border_win_options .title = new_title
181
- self .contents , self .title_ranges = Border ._create_lines (self .content_win_options , self ._border_win_options )
182
+ self .contents , self .title_ranges = Border ._create_lines (
183
+ self .content_win_id ,
184
+ self .content_win_options ,
185
+ self ._border_win_options
186
+ )
182
187
vim .api .nvim_buf_set_lines (self .bufnr , 0 , - 1 , false , self .contents )
183
188
184
189
set_title_highlights (self .bufnr , self .title_ranges , self ._border_win_options .titlehighlight )
@@ -201,6 +206,14 @@ function Border:__align_calc_config(content_win_options, border_win_options)
201
206
bot = " ═" ,
202
207
})
203
208
209
+ -- Ensure the relevant contents and border win_options are set
210
+ self ._border_win_options = border_win_options
211
+ self .content_win_options = content_win_options
212
+ -- Update border characters and title_ranges
213
+ self .contents , self .title_ranges = Border ._create_lines (self .content_win_id , content_win_options , border_win_options )
214
+
215
+ vim .api .nvim_buf_set_lines (self .bufnr , 0 , - 1 , false , self .contents )
216
+
204
217
local thickness = border_win_options .border_thickness
205
218
local nvim_win_config = {
206
219
anchor = content_win_options .anchor ,
@@ -215,14 +228,6 @@ function Border:__align_calc_config(content_win_options, border_win_options)
215
228
focusable = vim .F .if_nil (border_win_options .focusable , false ),
216
229
}
217
230
218
- -- Ensure the relevant contests and border win_options are set
219
- self ._border_win_options = border_win_options
220
- self .content_win_options = content_win_options
221
- -- Update border characters and title_ranges
222
- self .contents , self .title_ranges = Border ._create_lines (content_win_options , border_win_options )
223
-
224
- vim .api .nvim_buf_set_lines (self .bufnr , 0 , - 1 , false , self .contents )
225
-
226
231
return nvim_win_config
227
232
end
228
233
0 commit comments