Skip to content

Commit

Permalink
limit to two highlight groups for line rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-courtis committed Dec 25, 2023
1 parent 4a24950 commit 2569b24
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
13 changes: 8 additions & 5 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -789,8 +789,8 @@ Use nvim-tree in a floating window.
==============================================================================
5.3 OPTS: RENDERER *nvim-tree-opts-renderer*

Highlight precedence:
cut > copied > diagnostics > bookmarked > modified > opened > git
Highlight precedence, additive:
git < opened < modified < bookmarked < diagnostics < copied < cut

*nvim-tree.renderer.add_trailing*
Appends a trailing slash to folder names.
Expand Down Expand Up @@ -894,8 +894,8 @@ Configuration options for tree indent markers.
*nvim-tree.renderer.icons*
Configuration options for icons.

Icon sign column precedence:
diagnostics > bookmarked > modified > git
Icon order and sign column precedence:
git < modified < bookmarked < diagnostics

*nvim-tree.renderer.icons.web_devicons*
Configure optional plugin `"nvim-tree/nvim-web-devicons"`
Expand Down Expand Up @@ -2222,6 +2222,9 @@ as per |:highlight|

Default linked group or definition follows name.

neovim 0.9 has a limit of two highlight groups per range. The two highest
priority groups as per |nvim-tree-opts-renderer| will be used.

Standard: >
NvimTreeNormal Normal
NvimTreeNormalFloat NormalFloat
Expand Down Expand Up @@ -2340,7 +2343,7 @@ Diagnostics Folder Highlight: >
==============================================================================
8.1 HIGHLIGHT OVERHAUL *nvim-tree-highlight-overhaul*

2023/10/XX revision xxxxx made significant highlighting changes, some breaking:
2023-12: significant highlighting changes, some breaking:

- Full cterm support.
- Standard vim highlight groups such |DiagnosticUnderlineError| are now the
Expand Down
15 changes: 12 additions & 3 deletions lua/nvim-tree/renderer/builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,16 @@ function Builder:configure_group_name_modifier(group_name_modifier)
return self
end

function Builder:_insert_highlight(group, start, end_)
table.insert(self.highlights, { group, self.index, start, end_ or -1 })
--- Insert ranged highlight groups into self.highlights
--- neovim 0.9 is limited to two highlight groups for a range so choose the highest two
--- @param groups string[]
--- @param start number
--- @param end_ number|nil
function Builder:_insert_highlight(groups, start, end_)
local top_two_groups = {}
table.insert(top_two_groups, groups[#groups - 1])
table.insert(top_two_groups, groups[#groups])
table.insert(self.highlights, { top_two_groups, self.index, start, end_ or -1 })
end

function Builder:_insert_line(line)
Expand Down Expand Up @@ -271,7 +279,8 @@ function Builder:_build_line(node, idx, num_children)
end

-- highighting
for _, d in ipairs(self.decorators) do
for i = #self.decorators, 1, -1 do
local d = self.decorators[i]
local icon_group, name_group = d:groups_icon_name(node)
table.insert(icon.hl, icon_group)
table.insert(name.hl, name_group)
Expand Down

0 comments on commit 2569b24

Please sign in to comment.