@@ -98,6 +98,43 @@ function popup.create(what, vim_options)
98
98
local win_opts = {}
99
99
win_opts .relative = " editor"
100
100
101
+ -- Feels like maxheight, minheight, maxwidth, minwidth will all be related
102
+ --
103
+ -- maxheight Maximum height of the contents, excluding border and padding.
104
+ -- minheight Minimum height of the contents, excluding border and padding.
105
+ -- maxwidth Maximum width of the contents, excluding border, padding and scrollbar.
106
+ -- minwidth Minimum width of the contents, excluding border, padding and scrollbar.
107
+ local width = vim_options .width or 1
108
+ local height
109
+ if type (what ) == " number" then
110
+ height = vim .api .nvim_buf_line_count (what )
111
+ else
112
+ for _ , v in ipairs (what ) do
113
+ width = math.max (width , # v )
114
+ end
115
+ height = # what
116
+ end
117
+ win_opts .width = utils .bounded (width , vim_options .minwidth , vim_options .maxwidth )
118
+ win_opts .height = utils .bounded (height , vim_options .minheight , vim_options .maxheight )
119
+
120
+ -- pos
121
+ --
122
+ -- Using "topleft", "topright", "botleft", "botright" defines what corner of the popup "line"
123
+ -- and "col" are used for. When not set "topleft" behaviour is used.
124
+ -- Alternatively "center" can be used to position the popup in the center of the Neovim window,
125
+ -- in which case "line" and "col" are ignored.
126
+ if vim_options .pos then
127
+ if vim_options .pos == " center" then
128
+ vim_options .line = 0
129
+ vim_options .col = 0
130
+ win_opts .anchor = " NW"
131
+ else
132
+ win_opts .anchor = popup ._pos_map [vim_options .pos ]
133
+ end
134
+ else
135
+ win_opts .anchor = " NW" -- This is the default, but makes `posinvert` easier to implement
136
+ end
137
+
101
138
local cursor_relative_pos = function (pos_str , dim )
102
139
assert (string.find (pos_str , " ^cursor" ), " Invalid value for " .. dim )
103
140
win_opts .relative = " cursor"
@@ -110,37 +147,24 @@ function popup.create(what, vim_options)
110
147
return line
111
148
end
112
149
113
- if vim_options .line then
150
+ if vim_options .line and vim_options . line ~= 0 then
114
151
if type (vim_options .line ) == " string" then
115
152
win_opts .row = cursor_relative_pos (vim_options .line , " row" )
116
153
else
117
- win_opts .row = vim_options .line
154
+ win_opts .row = vim_options .line - 1
118
155
end
119
156
else
120
- -- TODO: It says it needs to be "vertically cenetered"?...
121
- -- wut is that.
122
- win_opts .row = 0
157
+ win_opts .row = math.floor ((vim .o .lines - win_opts .height ) / 2 )
123
158
end
124
159
125
- if vim_options .col then
160
+ if vim_options .col and vim_options . col ~= 0 then
126
161
if type (vim_options .col ) == " string" then
127
162
win_opts .col = cursor_relative_pos (vim_options .col , " col" )
128
163
else
129
- win_opts .col = vim_options .col
164
+ win_opts .col = vim_options .col - 1
130
165
end
131
166
else
132
- -- TODO: It says it needs to be "horizontally cenetered"?...
133
- win_opts .col = 0
134
- end
135
-
136
- if vim_options .pos then
137
- if vim_options .pos == " center" then
138
- -- TODO: Do centering..
139
- else
140
- win_opts .anchor = popup ._pos_map [vim_options .pos ]
141
- end
142
- else
143
- win_opts .anchor = " NW" -- This is the default, but makes `posinvert` easier to implement
167
+ win_opts .col = math.floor ((vim .o .columns - win_opts .width ) / 2 )
144
168
end
145
169
146
170
-- , fixed When FALSE (the default), and:
@@ -153,25 +177,6 @@ function popup.create(what, vim_options)
153
177
154
178
win_opts .style = " minimal"
155
179
156
- -- Feels like maxheight, minheight, maxwidth, minwidth will all be related
157
- --
158
- -- maxheight Maximum height of the contents, excluding border and padding.
159
- -- minheight Minimum height of the contents, excluding border and padding.
160
- -- maxwidth Maximum width of the contents, excluding border, padding and scrollbar.
161
- -- minwidth Minimum width of the contents, excluding border, padding and scrollbar.
162
- local width = vim_options .width or 1
163
- local height
164
- if type (what ) == " number" then
165
- height = vim .api .nvim_buf_line_count (what )
166
- else
167
- for _ , v in ipairs (what ) do
168
- width = math.max (width , # v )
169
- end
170
- height = # what
171
- end
172
- win_opts .width = utils .bounded (width , vim_options .minwidth , vim_options .maxwidth )
173
- win_opts .height = utils .bounded (height , vim_options .minheight , vim_options .maxheight )
174
-
175
180
-- posinvert, When FALSE the value of "pos" is always used. When
176
181
-- , TRUE (the default) and the popup does not fit
177
182
-- , vertically and there is more space on the other side
0 commit comments