@@ -23,7 +23,7 @@ describe('inline_input', function()
2323
2424 after_each (function ()
2525 if vim .api .nvim_win_is_valid (anchor_win ) then
26- vim .api .nvim_win_close ( anchor_win , true )
26+ pcall ( vim .api .nvim_win_close , anchor_win , true )
2727 end
2828 if vim .api .nvim_buf_is_valid (anchor_buf ) then
2929 vim .api .nvim_buf_delete (anchor_buf , { force = true })
@@ -45,6 +45,17 @@ describe('inline_input', function()
4545 return input
4646 end
4747
48+ local function use_regular_anchor ()
49+ vim .api .nvim_win_close (anchor_win , true )
50+ anchor_win = vim .api .nvim_get_current_win ()
51+ vim .api .nvim_win_set_buf (anchor_win , anchor_buf )
52+ vim .wo [anchor_win ].wrap = false
53+ vim .wo [anchor_win ].signcolumn = ' no'
54+ vim .wo [anchor_win ].foldcolumn = ' 0'
55+ vim .wo [anchor_win ].number = false
56+ vim .wo [anchor_win ].relativenumber = false
57+ end
58+
4859 local function change_text (input , text , expected_height )
4960 vim .api .nvim_buf_set_lines (input .buf , 0 , 1 , false , { text })
5061 vim .api .nvim_exec_autocmds (' TextChangedI' , { buffer = input .buf , modeline = false })
@@ -162,13 +173,15 @@ describe('inline_input', function()
162173 end )
163174
164175 it (' shrinks its opening width before the right border reaches the editor edge' , function ()
176+ use_regular_anchor ()
165177 local col = vim .api .nvim_win_get_width (anchor_win ) - 2
166178 local input = open_input (0 , col )
167179 local anchor = vim .fn .screenpos (anchor_win , 1 , col + 1 )
168180 local width = vim .api .nvim_win_get_config (input .win ).width
181+ local position = vim .api .nvim_win_get_position (input .win )
169182
170- assert .equals (math.min (50 , vim .o .columns - anchor .col - 1 ), width )
171- assert .is_true (anchor . col + width + 1 <= vim .o .columns )
183+ assert .equals (math.max ( 1 , math. min (50 , vim .o .columns - anchor .col - 1 ) ), width )
184+ assert .is_true (position [ 2 ] + width + 2 <= vim .o .columns )
172185 input .close ()
173186 end )
174187
@@ -185,6 +198,43 @@ describe('inline_input', function()
185198 input .close ()
186199 end )
187200
201+ it (' keeps its rounded border inside the editor at the bottom-right edge' , function ()
202+ vim .api .nvim_win_close (anchor_win , true )
203+ vim .cmd (' botright 10vnew' )
204+ vim .cmd (' botright 2new' )
205+ anchor_win = vim .api .nvim_get_current_win ()
206+ vim .api .nvim_win_set_buf (anchor_win , anchor_buf )
207+ vim .wo [anchor_win ].wrap = false
208+ vim .wo [anchor_win ].signcolumn = ' no'
209+ vim .wo [anchor_win ].foldcolumn = ' 0'
210+
211+ local input = open_input (0 , vim .api .nvim_win_get_width (anchor_win ) - 3 )
212+ local position = vim .api .nvim_win_get_position (input .win )
213+ local window_config = vim .api .nvim_win_get_config (input .win )
214+
215+ assert .is_true (
216+ position [2 ] + window_config .width + 2 <= vim .o .columns ,
217+ vim .inspect ({ position = position , config = window_config , columns = vim .o .columns , lines = vim .o .lines })
218+ )
219+ assert .is_true (
220+ position [1 ] + window_config .height + 2 <= vim .o .lines ,
221+ vim .inspect ({ position = position , config = window_config , columns = vim .o .columns , lines = vim .o .lines })
222+ )
223+ input .close ()
224+ vim .cmd (' only' )
225+ end )
226+
227+ it (' removes its WinClosed watcher after closing' , function ()
228+ local before = # vim .api .nvim_get_autocmds ({ event = ' WinClosed' })
229+
230+ for _ = 1 , 5 do
231+ local input = open_input (0 , 0 )
232+ input .close ()
233+ end
234+
235+ assert .equals (before , # vim .api .nvim_get_autocmds ({ event = ' WinClosed' }))
236+ end )
237+
188238 it (' resizes after multiline text changes outside insert mode' , function ()
189239 local input = open_input (0 , 0 )
190240 local lines = {
@@ -230,6 +280,34 @@ describe('inline_input', function()
230280 assert .equals (1 , cancelled )
231281 end )
232282
283+ it (' returns the draft and closes when its anchor window closes' , function ()
284+ local draft
285+ local cancelled = 0
286+ local input = inline_input .open ({
287+ win = anchor_win ,
288+ row = 0 ,
289+ col = 0 ,
290+ on_submit = function () end ,
291+ on_cancel = function ()
292+ cancelled = cancelled + 1
293+ end ,
294+ on_leave = function (text )
295+ draft = text
296+ end ,
297+ })
298+ assert .is_true (vim .wait (50 , function ()
299+ return vim .api .nvim_get_current_win () == input .win
300+ end ))
301+
302+ local lines = { ' first line' , ' second line' }
303+ vim .api .nvim_buf_set_lines (input .buf , 0 , - 1 , false , lines )
304+ vim .api .nvim_win_close (anchor_win , true )
305+
306+ assert .is_false (vim .api .nvim_win_is_valid (input .win ))
307+ assert .equals (table.concat (lines , ' \n ' ), draft )
308+ assert .equals (1 , cancelled )
309+ end )
310+
233311 it (' submits every character from a wrapped mixed-language line' , function ()
234312 local submitted
235313 local text = ' English 中文 mixed ' .. string.rep (' 长文本' , 40 )
0 commit comments