@@ -391,6 +391,99 @@ layout_strategies.center = make_documented_layout("center", vim.tbl_extend("erro
391
391
}
392
392
end )
393
393
394
+ --- Cursor layout dynamically positioned below the cursor if possible.
395
+ --- If there is no place below the cursor it will be placed above.
396
+ ---
397
+ --- <pre>
398
+ --- ┌──────────────────────────────────────────────────┐
399
+ --- │ │
400
+ --- │ █ │
401
+ --- │ ┌──────────────┐┌─────────────────────┐ │
402
+ --- │ │ Prompt ││ Preview │ │
403
+ --- │ ├──────────────┤│ Preview │ │
404
+ --- │ │ Result ││ Preview │ │
405
+ --- │ │ Result ││ Preview │ │
406
+ --- │ └──────────────┘└─────────────────────┘ │
407
+ --- │ █ │
408
+ --- │ │
409
+ --- │ │
410
+ --- │ │
411
+ --- │ │
412
+ --- │ │
413
+ --- └──────────────────────────────────────────────────┘
414
+ --- </pre>
415
+ layout_strategies .cursor = make_documented_layout (" cursor" , vim .tbl_extend (" error" , shared_options , {
416
+ preview_width = { " Change the width of Telescope's preview window" , " See |resolver.resolve_width()|" , },
417
+ preview_cutoff = " When columns are less than this value, the preview will be disabled" ,
418
+ }), function (self , max_columns , max_lines , layout_config )
419
+ local initial_options = p_window .get_initial_window_options (self )
420
+ local preview = initial_options .preview
421
+ local results = initial_options .results
422
+ local prompt = initial_options .prompt
423
+
424
+ local height_opt = layout_config .height
425
+ local height = resolve .resolve_height (height_opt )(self , max_columns , max_lines )
426
+
427
+ local width_opt = layout_config .width
428
+ local width = resolve .resolve_width (width_opt )(self , max_columns , max_lines )
429
+
430
+ local max_width = (width > max_columns and max_columns or width )
431
+
432
+ local bs = get_border_size (self )
433
+
434
+ prompt .height = 1
435
+ results .height = height
436
+ preview .height = results .height + prompt .height + bs
437
+
438
+ if self .previewer and max_columns >= layout_config .preview_cutoff then
439
+ preview .width = resolve .resolve_width (if_nil (layout_config .preview_width , function (_ , cols )
440
+ -- By default, previewer takes 2/3 of the layout
441
+ return 2 * math.floor (max_width / 3 )
442
+ end ))(self , max_width , max_lines )
443
+ else
444
+ preview .width = 0
445
+ end
446
+
447
+ prompt .width = max_width - preview .width
448
+ results .width = prompt .width
449
+
450
+ local total_height = preview .height + (bs * 2 )
451
+ local total_width = prompt .width + (bs * 2 ) + preview .width + bs
452
+
453
+ local position = vim .api .nvim_win_get_position (0 )
454
+ local top_left = {
455
+ line = vim .fn .winline () + position [1 ] + bs ,
456
+ col = vim .fn .wincol () + position [2 ]
457
+ }
458
+ local bot_right = {
459
+ line = top_left .line + total_height - 1 ,
460
+ col = top_left .col + total_width - 1
461
+ }
462
+
463
+ if bot_right .line > max_lines then
464
+ -- position above current line
465
+ top_left .line = top_left .line - total_height - 1
466
+ end
467
+ if bot_right .col >= max_columns then
468
+ -- cap to the right of the screen
469
+ top_left .col = max_columns - total_width
470
+ end
471
+
472
+ prompt .line = top_left .line
473
+ results .line = prompt .line + bs + 1
474
+ preview .line = prompt .line
475
+
476
+ prompt .col = top_left .col
477
+ results .col = prompt .col
478
+ preview .col = results .col + (bs * 2 ) + results .width
479
+
480
+ return {
481
+ preview = self .previewer and preview .width > 0 and preview ,
482
+ results = results ,
483
+ prompt = prompt
484
+ }
485
+ end )
486
+
394
487
--- Vertical layout stacks the items on top of each other.
395
488
--- Particularly useful with thinner windows.
396
489
---
0 commit comments