241
241
---
242
242
layout_strategies .horizontal = make_documented_layout (' horizontal' , vim .tbl_extend (" error" , shared_options , {
243
243
preview_width = { " Change the width of Telescope's preview window" , " See |resolver.resolve_width()|" , },
244
- preview_cutoff = " When columns are less than this value, the preview will be disabled" ,
244
+ preview_cutoff = {" Decides whether to display preview based on size of window." ,
245
+ " See |resolver.resolve_cutoff|" },
245
246
prompt_position = { " Where to place prompt window." , " Available Values: 'bottom', 'top'" },
246
247
}), function (self , max_columns , max_lines , layout_config )
247
248
local initial_options = p_window .get_initial_window_options (self )
@@ -257,11 +258,11 @@ layout_strategies.horizontal = make_documented_layout('horizontal', vim.tbl_exte
257
258
local picker_height = resolve .resolve_height (height_opt )(self , max_columns , max_lines )
258
259
local height_padding = math.floor ((max_lines - picker_height )/ 2 )
259
260
260
- if self .previewer then
261
+ local prev_cutoff_func = resolve .resolve_cutoff (layout_config .preview_cutoff )
262
+ local has_preview = self .previewer and prev_cutoff_func (self , max_columns , max_lines )
263
+ if has_preview then
261
264
preview .width = resolve .resolve_width (layout_config .preview_width or function (_ , cols )
262
- if not self .previewer or cols < layout_config .preview_cutoff then
263
- return 0
264
- elseif cols < 150 then
265
+ if cols < 150 then
265
266
return math.floor (cols * 0.4 )
266
267
elseif cols < 200 then
267
268
return 80
@@ -279,7 +280,7 @@ layout_strategies.horizontal = make_documented_layout('horizontal', vim.tbl_exte
279
280
prompt .height = 1
280
281
results .height = picker_height - prompt .height - 2
281
282
282
- if self . previewer then
283
+ if has_preview then
283
284
preview .height = picker_height
284
285
else
285
286
preview .height = 0
342
343
---
343
344
layout_strategies .center = make_documented_layout (" center" , vim .tbl_extend (" error" , shared_options , {
344
345
-- TODO: Should this be based on rows here?
345
- preview_cutoff = " When columns are less than this value, the preview will be disabled" ,
346
+ preview_cutoff = {" Decides whether to display preview based on size of window." ,
347
+ " See |resolver.resolve_cutoff|" },
346
348
}), function (self , max_columns , max_lines ,layout_config )
347
349
local initial_options = p_window .get_initial_window_options (self )
348
350
local preview = initial_options .preview
@@ -375,9 +377,12 @@ layout_strategies.center = make_documented_layout("center", vim.tbl_extend("erro
375
377
results .line = prompt .line + 1 + (bs )
376
378
377
379
preview .line = 1
378
- preview .height = math.floor (prompt .line - (2 + bs ))
379
380
380
- if not self .previewer or max_columns < layout_config .preview_cutoff then
381
+ local prev_cutoff_func = resolve .resolve_cutoff (layout_config .preview_cutoff )
382
+ local has_preview = self .previewer and prev_cutoff_func (self , max_columns , max_lines )
383
+ if has_preview then
384
+ preview .height = math.floor (prompt .line - (2 + bs ))
385
+ else
381
386
preview .height = 0
382
387
end
383
388
@@ -386,7 +391,7 @@ layout_strategies.center = make_documented_layout("center", vim.tbl_extend("erro
386
391
preview .col = results .col
387
392
388
393
return {
389
- preview = self .previewer and preview .width > 0 and preview ,
394
+ preview = self .previewer and preview .height > 0 and preview ,
390
395
results = results ,
391
396
prompt = prompt
392
397
}
@@ -416,7 +421,10 @@ end)
416
421
--- @eval { ["description"] = require("telescope.pickers.layout_strategies")._format("vertical") }
417
422
---
418
423
layout_strategies .vertical = make_documented_layout (" vertical" , vim .tbl_extend (" error" , shared_options , {
419
- preview_height = { " Change the height of Telescope's preview window" , " See |resolver.resolve_height()|" },
424
+ preview_height = { " Change the height of Telescope's preview window" ,
425
+ " See |resolver.resolve_height()|" },
426
+ preview_cutoff = {" Decides whether to display preview based on size of window." ,
427
+ " See |resolver.resolve_cutoff|" },
420
428
}), function (self , max_columns , max_lines , layout_config )
421
429
422
430
local initial_options = p_window .get_initial_window_options (self )
@@ -425,24 +433,26 @@ layout_strategies.vertical = make_documented_layout("vertical", vim.tbl_extend("
425
433
local prompt = initial_options .prompt
426
434
427
435
local width_opt = layout_config .width
428
- local picker_width = resolve .resolve_width (width_opt )(self ,max_columns ,max_lines )
436
+ local picker_width = resolve .resolve_width (width_opt )(self , max_columns , max_lines )
429
437
local width_padding = math.floor ((max_columns - picker_width )/ 2 )
430
438
431
439
local height_opt = layout_config .height
432
- local picker_height = resolve .resolve_height (height_opt )(self ,max_columns ,max_lines )
440
+ local picker_height = resolve .resolve_height (height_opt )(self , max_columns , max_lines )
433
441
local height_padding = math.floor ((max_lines - picker_height )/ 2 )
434
442
435
- if not self . previewer then
436
- preview . width = 0
437
- else
443
+ local prev_cutoff_func = resolve . resolve_cutoff ( layout_config . preview_cutoff )
444
+ local has_preview = self . previewer and prev_cutoff_func ( self , max_columns , max_lines )
445
+ if has_preview then
438
446
preview .width = picker_width
447
+ else
448
+ preview .width = 0
439
449
end
440
450
results .width = picker_width
441
451
prompt .width = picker_width
442
452
443
453
local preview_total = 0
444
454
preview .height = 0
445
- if self . previewer then
455
+ if has_preview then
446
456
preview .height = resolve .resolve_height (
447
457
layout_config .preview_height or 0.5
448
458
)(self , max_columns , picker_height )
@@ -455,7 +465,7 @@ layout_strategies.vertical = make_documented_layout("vertical", vim.tbl_extend("
455
465
456
466
results .col , preview .col , prompt .col = width_padding , width_padding , width_padding
457
467
458
- if self . previewer then
468
+ if has_preview then
459
469
if not layout_config .mirror then
460
470
preview .line = height_padding
461
471
results .line = preview .line + preview .height + 2
@@ -471,7 +481,7 @@ layout_strategies.vertical = make_documented_layout("vertical", vim.tbl_extend("
471
481
end
472
482
473
483
return {
474
- preview = self .previewer and preview .width > 0 and preview ,
484
+ preview = self .previewer and preview .height > 0 and preview ,
475
485
results = results ,
476
486
prompt = prompt
477
487
}
@@ -568,7 +578,7 @@ layout_strategies.bottom_pane = make_documented_layout('bottom_pane', vim.tbl_ex
568
578
local prompt = initial_options .prompt
569
579
local preview = initial_options .preview
570
580
571
- local result_height = resolve .resolve_height (layout_config .height )(self ,max_columns ,max_lines ) or 25
581
+ local result_height = resolve .resolve_height (layout_config .height )(self , max_columns , max_lines ) or 25
572
582
573
583
local prompt_width = max_columns
574
584
local col = 0
0 commit comments