diff options
| author | fdschmidt93 <39233597+fdschmidt93@users.noreply.github.com> | 2021-09-27 15:24:35 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-27 15:24:35 +0200 |
| commit | a6c7498bdcd661e86ec0c1181ed50024beb540f7 (patch) | |
| tree | 3b85b283bda8275160057252b74a75aff4abdbd2 /lua/telescope/previewers/utils.lua | |
| parent | 87471bc3ff83ddfc47d18c2f0f096e97e6a557bf (diff) | |
feat: filetype_hook & improved docs; fix preview partial override (#1273)
Diffstat (limited to 'lua/telescope/previewers/utils.lua')
| -rw-r--r-- | lua/telescope/previewers/utils.lua | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/lua/telescope/previewers/utils.lua b/lua/telescope/previewers/utils.lua index 234eb0c..8acbd58 100644 --- a/lua/telescope/previewers/utils.lua +++ b/lua/telescope/previewers/utils.lua @@ -1,4 +1,7 @@ local context_manager = require "plenary.context_manager" +local ts_utils = require "telescope.utils" +local strings = require "plenary.strings" +local conf = require("telescope.config").values local has_ts, _ = pcall(require, "nvim-treesitter") local _, ts_configs = pcall(require, "nvim-treesitter.configs") @@ -66,7 +69,10 @@ end utils.highlighter = function(bufnr, ft, opts) opts = opts or {} opts.preview = opts.preview or {} - opts.preview.treesitter = vim.F.if_nil(opts.preview.treesitter, true) + opts.preview.treesitter = vim.F.if_nil( + opts.preview.treesitter, + type(conf.preview) == "table" and conf.preview.treesitter + ) local ts_highlighting = opts.preview.treesitter == true or type(opts.preview.treesitter) == "table" and vim.tbl_contains(opts.preview.treesitter, ft) @@ -127,4 +133,41 @@ utils.ts_highlighter = function(bufnr, ft) return false end +utils.set_preview_message = function(bufnr, winid, message, fillchar) + fillchar = vim.F.if_nil(fillchar, "╱") + local height = vim.api.nvim_win_get_height(winid) + local width = vim.api.nvim_win_get_width(winid) + vim.api.nvim_buf_set_lines( + bufnr, + 0, + -1, + false, + ts_utils.repeated_table(height, table.concat(ts_utils.repeated_table(width, fillchar), "")) + ) + local anon_ns = vim.api.nvim_create_namespace "" + local padding = table.concat(ts_utils.repeated_table(#message + 4, " "), "") + local lines = { + padding, + " " .. message .. " ", + padding, + } + vim.api.nvim_buf_set_extmark( + bufnr, + anon_ns, + 0, + 0, + { end_line = height, hl_group = "TelescopePreviewMessageFillchar" } + ) + local col = math.floor((width - strings.strdisplaywidth(lines[2])) / 2) + for i, line in ipairs(lines) do + vim.api.nvim_buf_set_extmark( + bufnr, + anon_ns, + math.floor(height / 2) - 1 + i, + 0, + { virt_text = { { line, "TelescopePreviewMessage" } }, virt_text_pos = "overlay", virt_text_win_col = col } + ) + end +end + return utils |
