@@ -441,9 +441,13 @@ function Picker:find()
441
441
[[ autocmd BufLeave <buffer> ++nested ++once :silent lua require('telescope.pickers').on_close_prompt(%s)]] ,
442
442
prompt_bufnr )
443
443
444
+ local on_vim_resize = string.format (
445
+ [[ autocmd VimResized <buffer> ++nested :silent lua require('telescope.pickers').on_resize_window(%s)]] ,
446
+ prompt_bufnr )
444
447
vim .cmd ([[ augroup PickerInsert]] )
445
448
vim .cmd ([[ au!]] )
446
449
vim .cmd ( on_buf_leave )
450
+ vim .cmd ( on_vim_resize )
447
451
vim .cmd ([[ augroup END]] )
448
452
449
453
self .prompt_bufnr = prompt_bufnr
@@ -483,6 +487,39 @@ function Picker:find()
483
487
end
484
488
end
485
489
490
+ function Picker :recalculate_layout ()
491
+ local line_count = vim .o .lines - vim .o .cmdheight
492
+ if vim .o .laststatus ~= 0 then
493
+ line_count = line_count - 1
494
+ end
495
+
496
+ local popup_opts = self :get_window_options (vim .o .columns , line_count )
497
+ -- `popup.nvim` massaging so people don't have to remember minheight shenanigans
498
+ popup_opts .results .minheight = popup_opts .results .height
499
+ popup_opts .prompt .minheight = popup_opts .prompt .height
500
+ if popup_opts .preview then
501
+ popup_opts .preview .minheight = popup_opts .preview .height
502
+ end
503
+
504
+ local status = state .get_status (self .prompt_bufnr )
505
+ local prompt_win = status .prompt_win
506
+ local results_win = status .results_win
507
+ local preview_win = status .preview_win
508
+ popup .resize (results_win , popup_opts .results )
509
+
510
+
511
+ if popup_opts .preview then
512
+ popup .resize (preview_win , popup_opts .preview )
513
+ end
514
+
515
+ popup .resize (prompt_win , popup_opts .prompt )
516
+
517
+ -- Temporarily disabled: Draw the screen ASAP. This makes things feel speedier.
518
+ -- vim.cmd [[redraw]]
519
+
520
+ self .max_results = popup_opts .results .height
521
+ end
522
+
486
523
function Picker :hide_preview ()
487
524
-- 1. Hide the window (and border)
488
525
-- 2. Resize prompt & results windows accordingly
@@ -1137,6 +1174,22 @@ function pickers.on_close_prompt(prompt_bufnr)
1137
1174
picker .close_windows (status )
1138
1175
end
1139
1176
1177
+ function pickers .on_resize_window (prompt_bufnr )
1178
+ print (' resizing' .. prompt_bufnr )
1179
+ local status = state .get_status (prompt_bufnr )
1180
+ local picker = status .picker
1181
+
1182
+ -- if picker.sorter then
1183
+ -- picker.sorter:_destroy()
1184
+ -- end
1185
+
1186
+ -- if picker.previewer then
1187
+ -- picker.previewer:teardown()
1188
+ -- end
1189
+
1190
+ picker :recalculate_layout ()
1191
+ end
1192
+
1140
1193
--- Get the prompt text without the prompt prefix.
1141
1194
function Picker :_get_prompt ()
1142
1195
return vim .api .nvim_buf_get_lines (self .prompt_bufnr , 0 , 1 , false )[1 ]:sub (# self .prompt_prefix + 1 )
0 commit comments