@@ -261,7 +261,11 @@ function Dialog:format_dialog(output, config)
261261 local end_line = output :get_line_count ()
262262
263263 if config .border_hl then
264- formatter .add_vertical_border (output , start_line + 1 , end_line , config .border_hl , - 2 )
264+ local border_end = end_line
265+ if config .extend_border_to_trailing_blank then
266+ border_end = border_end + 1
267+ end
268+ formatter .add_vertical_border (output , start_line + 1 , border_end , config .border_hl , - 2 )
265269 end
266270
267271 output :add_line (' ' )
@@ -277,15 +281,22 @@ function Dialog:format_options(output, options)
277281 label = label .. ' - ' .. option .description
278282 end
279283
280- local line_idx = output :get_line_count ()
281284 local is_selected = self ._selected_index == i
282285 local line_text = is_selected and string.format (' %d. %s ' , i , label ) or string.format (' %d. %s' , i , label )
283286
284- output :add_line (line_text )
287+ -- Output uses 0-based indexing for extmarks. The correct target for
288+ -- extmarks is the previous line count (0-based) because add_line will
289+ -- append a new line and increase the 1-based line count. Capture the
290+ -- current count first and then add the line so we can use that 0-based
291+ -- index for extmarks.
292+ -- add_line returns a 1-based line index; Output extmarks use 0-based
293+ -- keys, so subtract 1 to get the correct extmark key.
294+ local added_idx = output :add_line (line_text )
285295
286296 if is_selected then
287- output :add_extmark (line_idx , { line_hl_group = ' OpencodeDialogOptionHover' } --[[ @as OutputExtmark]] )
288- output :add_extmark (line_idx , {
297+ local extmark_idx = added_idx - 1
298+ output :add_extmark (extmark_idx , { line_hl_group = ' OpencodeDialogOptionHover' } --[[ @as OutputExtmark]] )
299+ output :add_extmark (extmark_idx , {
289300 start_col = 2 ,
290301 virt_text = { { ' › ' , ' OpencodeDialogOptionHover' } },
291302 virt_text_pos = ' overlay' ,
@@ -309,11 +320,16 @@ function Dialog:_setup_keymaps()
309320 if keymaps .up then
310321 for _ , key in ipairs (keymaps .up ) do
311322 if key and key ~= ' ' then
312- vim .keymap .set (' n' , key , function ()
313- self :navigate (- 1 )
314- end , vim .tbl_extend (' force' , keymap_opts , {
315- desc = ' Dialog: navigate up' ,
316- }))
323+ vim .keymap .set (
324+ ' n' ,
325+ key ,
326+ function ()
327+ self :navigate (- 1 )
328+ end ,
329+ vim .tbl_extend (' force' , keymap_opts , {
330+ desc = ' Dialog: navigate up' ,
331+ })
332+ )
317333 table.insert (self ._keymaps , key )
318334 end
319335 end
@@ -322,31 +338,46 @@ function Dialog:_setup_keymaps()
322338 if keymaps .down then
323339 for _ , key in ipairs (keymaps .down ) do
324340 if key and key ~= ' ' then
325- vim .keymap .set (' n' , key , function ()
326- self :navigate (1 )
327- end , vim .tbl_extend (' force' , keymap_opts , {
328- desc = ' Dialog: navigate down' ,
329- }))
341+ vim .keymap .set (
342+ ' n' ,
343+ key ,
344+ function ()
345+ self :navigate (1 )
346+ end ,
347+ vim .tbl_extend (' force' , keymap_opts , {
348+ desc = ' Dialog: navigate down' ,
349+ })
350+ )
330351 table.insert (self ._keymaps , key )
331352 end
332353 end
333354 end
334355
335356 if keymaps .select and keymaps .select ~= ' ' then
336- vim .keymap .set (' n' , keymaps .select , function ()
337- self :select ()
338- end , vim .tbl_extend (' force' , keymap_opts , {
339- desc = ' Dialog: select option' ,
340- }))
357+ vim .keymap .set (
358+ ' n' ,
359+ keymaps .select ,
360+ function ()
361+ self :select ()
362+ end ,
363+ vim .tbl_extend (' force' , keymap_opts , {
364+ desc = ' Dialog: select option' ,
365+ })
366+ )
341367 table.insert (self ._keymaps , keymaps .select )
342368 end
343369
344370 if keymaps .dismiss and keymaps .dismiss ~= ' ' then
345- vim .keymap .set (' n' , keymaps .dismiss , function ()
346- self :dismiss ()
347- end , vim .tbl_extend (' force' , keymap_opts , {
348- desc = ' Dialog: dismiss' ,
349- }))
371+ vim .keymap .set (
372+ ' n' ,
373+ keymaps .dismiss ,
374+ function ()
375+ self :dismiss ()
376+ end ,
377+ vim .tbl_extend (' force' , keymap_opts , {
378+ desc = ' Dialog: dismiss' ,
379+ })
380+ )
350381 table.insert (self ._keymaps , keymaps .dismiss )
351382 end
352383
@@ -355,15 +386,20 @@ function Dialog:_setup_keymaps()
355386 local number_keymap_opts = vim .tbl_extend (' force' , keymap_opts , { nowait = true })
356387 for i = 1 , math.min (option_count , 9 ) do
357388 local key = tostring (i )
358- vim .keymap .set (' n' , key , function ()
359- if not self ._active or not self ._config .check_focused () then
360- return
361- end
362- self ._selected_index = i
363- self ._config .on_select (i )
364- end , vim .tbl_extend (' force' , number_keymap_opts , {
365- desc = ' Dialog: select option ' .. key ,
366- }))
389+ vim .keymap .set (
390+ ' n' ,
391+ key ,
392+ function ()
393+ if not self ._active or not self ._config .check_focused () then
394+ return
395+ end
396+ self ._selected_index = i
397+ self ._config .on_select (i )
398+ end ,
399+ vim .tbl_extend (' force' , number_keymap_opts , {
400+ desc = ' Dialog: select option ' .. key ,
401+ })
402+ )
367403 table.insert (self ._keymaps , key )
368404 end
369405 end
0 commit comments