@@ -105,11 +105,53 @@ function win:update_size()
105
105
end
106
106
107
107
-- todo: fix nvim_win_text_height
108
+ -- @return number
108
109
function win :get_content_height ()
109
110
if not self :is_open () then return 0 end
110
111
return vim .api .nvim_win_text_height (self :get_win (), {}).all
111
112
end
112
113
114
+ --- @return { vertical : number , horizontal : number }
115
+ function win :get_border_size ()
116
+ if not self :is_open () then return { vertical = 0 , horizontal = 0 } end
117
+
118
+ local border = self .config .border
119
+ if border == ' none' then
120
+ return { vertical = 0 , horizontal = 0 }
121
+ elseif border == ' padded' then
122
+ return { vertical = 0 , horizontal = 1 }
123
+ elseif border == ' shadow' then
124
+ return { vertical = 1 , horizontal = 1 }
125
+ elseif type (border ) == ' string' then
126
+ return { vertical = 2 , horizontal = 2 }
127
+ elseif type (border ) == ' table' and border ~= nil then
128
+ -- borders can be a table of strings and act differently with different # of chars
129
+ -- so we normalize it: https://neovim.io/doc/user/api.html#nvim_open_win()
130
+ -- based on nvim-cmp
131
+ local resolved_border = {}
132
+ while # resolved_border <= 8 do
133
+ for _ , b in ipairs (border ) do
134
+ table.insert (resolved_border , type (b ) == ' string' and b or b [1 ])
135
+ end
136
+ end
137
+
138
+ local top = resolved_border [2 ] == ' ' and 0 or 1
139
+ local bottom = resolved_border [6 ] == ' ' and 0 or 1
140
+ local left = resolved_border [8 ] == ' ' and 0 or 1
141
+ local right = resolved_border [4 ] == ' ' and 0 or 1
142
+ return { vertical = top + bottom , horizontal = left + right }
143
+ end
144
+
145
+ return { vertical = 0 , horizontal = 0 }
146
+ end
147
+
148
+ --- @return number
149
+ function win :get_height ()
150
+ if not self :is_open () then return 0 end
151
+ return vim .api .nvim_win_get_height (self :get_win ()) + self :get_border_size ().vertical
152
+ end
153
+
154
+ --- @return number
113
155
function win :get_content_width ()
114
156
if not self :is_open () then return 0 end
115
157
local max_width = 0
@@ -119,6 +161,13 @@ function win:get_content_width()
119
161
return max_width
120
162
end
121
163
164
+ --- @return number
165
+ function win :get_width ()
166
+ if not self :is_open () then return 0 end
167
+ return vim .api .nvim_win_get_width (self :get_win ()) + self :get_border_size ().horizontal
168
+ end
169
+
170
+ --- @return { bufnr : number , start_line : number , end_line : number , horizontal_offset : number }
122
171
function win .get_screen_scroll_range ()
123
172
local bufnr = vim .api .nvim_win_get_buf (0 )
124
173
local line_count = vim .api .nvim_buf_line_count (bufnr )
0 commit comments