Skip to content

Commit

Permalink
fix: telescope extension can customize col widths
Browse files Browse the repository at this point in the history
* fix telescope highlights regression from #386

the highlighting for the symbol type and the symbol name were lost with
that change.

* fix: telescope highlighting accounts for multibyte characters

* telescope: allow to configure column widths

---------

Co-authored-by: Steven Arcangeli <[email protected]>
  • Loading branch information
emmanueltouzery and stevearc authored Oct 16, 2024
1 parent 603156d commit 8be4124
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,10 @@ The extension can be customized with the following options:
require("telescope").setup({
extensions = {
aerial = {
-- Set the width of the first two columns (the second
-- is relevant only when show_columns is set to 'both')
col1_width = 4,
col2_width = 30,
-- How to format the symbols
format_symbol = function(symbol_path, filetype)
if filetype == "json" or filetype == "yaml" then
Expand Down
16 changes: 12 additions & 4 deletions lua/telescope/_extensions/aerial.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ local pickers = require("telescope.pickers")
local telescope = require("telescope")

local ext_config = {
col1_width = 4,
col2_width = 30,
-- show_lines = true, -- deprecated in favor of show_columns
show_columns = "both", -- { "symbols", "lines", "both" }
format_symbol = function(symbol_path, filetype)
Expand Down Expand Up @@ -53,13 +55,13 @@ local function aerial_picker(opts)
local layout
if show_columns == "both" then
layout = {
{ width = 4 },
{ width = 30 },
{ width = ext_config.col1_width },
{ width = ext_config.col2_width },
{ remaining = true },
}
else
layout = {
{ width = 4 },
{ width = ext_config.col1_width },
{ remaining = true },
}
end
Expand Down Expand Up @@ -136,7 +138,13 @@ local function aerial_picker(opts)
if #entry.name > layout[2].width then
offset = offset + 2 -- '...' symbol
end
highlights = highlights_for_row(row, offset)
local col1_len = ext_config.col1_width + icon:len() - vim.api.nvim_strwidth(icon)
local col2_len = ext_config.col2_width + entry.name:len() - vim.api.nvim_strwidth(entry.name)
highlights = {
{ { 0, col1_len }, icon_hl },
{ { col1_len + 1, col1_len + 1 + col2_len + 1 }, name_hl },
}
vim.list_extend(highlights, highlights_for_row(row, offset))
end

return displayer(columns), highlights
Expand Down

0 comments on commit 8be4124

Please sign in to comment.