@@ -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,47 @@ 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 1new' )
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 col = vim .api .nvim_win_get_width (anchor_win ) - 3
212+ local anchor = vim .fn .screenpos (anchor_win , 1 , col + 1 )
213+ assert .equals (vim .o .lines - 2 , anchor .row )
214+
215+ local input = open_input (0 , col )
216+ local position = vim .api .nvim_win_get_position (input .win )
217+ local window_config = vim .api .nvim_win_get_config (input .win )
218+
219+ assert .is_true (
220+ position [2 ] + window_config .width + 2 <= vim .o .columns ,
221+ vim .inspect ({ position = position , config = window_config , columns = vim .o .columns , lines = vim .o .lines })
222+ )
223+ assert .is_true (
224+ position [1 ] + window_config .height + 2 <= vim .o .lines ,
225+ vim .inspect ({ position = position , config = window_config , columns = vim .o .columns , lines = vim .o .lines })
226+ )
227+ input .close ()
228+ vim .cmd (' only' )
229+ end )
230+
231+ it (' removes its WinClosed watcher after closing' , function ()
232+ local before = # vim .api .nvim_get_autocmds ({ event = ' WinClosed' })
233+
234+ for _ = 1 , 5 do
235+ local input = open_input (0 , 0 )
236+ input .close ()
237+ end
238+
239+ assert .equals (before , # vim .api .nvim_get_autocmds ({ event = ' WinClosed' }))
240+ end )
241+
188242 it (' resizes after multiline text changes outside insert mode' , function ()
189243 local input = open_input (0 , 0 )
190244 local lines = {
@@ -230,6 +284,34 @@ describe('inline_input', function()
230284 assert .equals (1 , cancelled )
231285 end )
232286
287+ it (' returns the draft and closes when its anchor window closes' , function ()
288+ local draft
289+ local cancelled = 0
290+ local input = inline_input .open ({
291+ win = anchor_win ,
292+ row = 0 ,
293+ col = 0 ,
294+ on_submit = function () end ,
295+ on_cancel = function ()
296+ cancelled = cancelled + 1
297+ end ,
298+ on_leave = function (text )
299+ draft = text
300+ end ,
301+ })
302+ assert .is_true (vim .wait (50 , function ()
303+ return vim .api .nvim_get_current_win () == input .win
304+ end ))
305+
306+ local lines = { ' first line' , ' second line' }
307+ vim .api .nvim_buf_set_lines (input .buf , 0 , - 1 , false , lines )
308+ vim .api .nvim_win_close (anchor_win , true )
309+
310+ assert .is_false (vim .api .nvim_win_is_valid (input .win ))
311+ assert .equals (table.concat (lines , ' \n ' ), draft )
312+ assert .equals (1 , cancelled )
313+ end )
314+
233315 it (' submits every character from a wrapped mixed-language line' , function ()
234316 local submitted
235317 local text = ' English 中文 mixed ' .. string.rep (' 长文本' , 40 )
0 commit comments