@@ -136,15 +136,8 @@ function popup.create(what, vim_options)
136
136
else
137
137
win_opts .anchor = popup ._pos_map [vim_options .pos ]
138
138
end
139
- end
140
-
141
- -- posinvert, When FALSE the value of "pos" is always used. When
142
- -- , TRUE (the default) and the popup does not fit
143
- -- , vertically and there is more space on the other side
144
- -- , then the popup is placed on the other side of the
145
- -- , position indicated by "line".
146
- if dict_default (vim_options , ' posinvert' , option_defaults ) then
147
- -- TODO: handle the invert thing
139
+ else
140
+ win_opts .anchor = " NW" -- This is the default, but makes `posinvert` easier to implement
148
141
end
149
142
150
143
-- , fixed When FALSE (the default), and:
@@ -157,7 +150,7 @@ function popup.create(what, vim_options)
157
150
158
151
win_opts .style = ' minimal'
159
152
160
- -- Feels like maxheigh , minheight, maxwidth, minwidth will all be related
153
+ -- Feels like maxheight , minheight, maxwidth, minwidth will all be related
161
154
--
162
155
-- maxheight Maximum height of the contents, excluding border and padding.
163
156
-- minheight Minimum height of the contents, excluding border and padding.
@@ -176,6 +169,25 @@ function popup.create(what, vim_options)
176
169
win_opts .width = utils .bounded (width , vim_options .minwidth , vim_options .maxwidth )
177
170
win_opts .height = utils .bounded (height , vim_options .minheight , vim_options .maxheight )
178
171
172
+ -- posinvert, When FALSE the value of "pos" is always used. When
173
+ -- , TRUE (the default) and the popup does not fit
174
+ -- , vertically and there is more space on the other side
175
+ -- , then the popup is placed on the other side of the
176
+ -- , position indicated by "line".
177
+ if dict_default (vim_options , ' posinvert' , option_defaults ) then
178
+ if win_opts .anchor == " NW" or win_opts .anchor == " NE" then
179
+ if win_opts .row + win_opts .height > vim .o .lines and win_opts .row * 2 > vim .o .lines then
180
+ -- Don't know why, but this is how vim adjusts it
181
+ win_opts .row = win_opts .row - win_opts .height - 2
182
+ end
183
+ elseif win_opts .anchor == " SW" or win_opts .anchor == " SE" then
184
+ if win_opts .row - win_opts .height < 0 and win_opts .row * 2 < vim .o .lines then
185
+ -- Don't know why, but this is how vim adjusts it
186
+ win_opts .row = win_opts .row + win_opts .height + 2
187
+ end
188
+ end
189
+ end
190
+
179
191
-- textprop, When present the popup is positioned next to a text
180
192
-- , property with this name and will move when the text
181
193
-- , property moves. Use an empty string to remove. See
0 commit comments