Skip to content

Commit 454178f

Browse files
committed
feat(#2411): bookmark highlight and icon placement
1 parent d627f8c commit 454178f

File tree

7 files changed

+58
-37
lines changed

7 files changed

+58
-37
lines changed

doc/nvim-tree-lua.txt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ Following is the default configuration. See |nvim-tree-opts| for details.
388388
highlight_diagnostics = false,
389389
highlight_opened_files = "none",
390390
highlight_modified = "none",
391-
highlight_bookmarks = false,
391+
highlight_bookmarks = "none",
392392
highlight_clipboard = "name",
393393
indent_markers = {
394394
enable = false,
@@ -780,7 +780,8 @@ Use nvim-tree in a floating window.
780780
==============================================================================
781781
5.3 OPTS: RENDERER *nvim-tree-opts-renderer*
782782

783-
Highlight precedence: git < opened < modified < diagnostics
783+
Highlight precedence:
784+
clipboard > diagnostics > bookmarked > modified > opened > git
784785

785786
*nvim-tree.renderer.add_trailing*
786787
Appends a trailing slash to folder names.
@@ -844,8 +845,9 @@ Value can be `"none"`, `"icon"`, `"name"` or `"all"`
844845
Type: `string`, Default `"none"`
845846

846847
*nvim-tree.renderer.highlight_bookmarks*
847-
Highlight bookmarked using the `NvimTreeBookmarkText` highlight group.
848-
Type: `boolean`, Default `false`
848+
Highlight bookmarked using the `NvimTreeBookmarkHL` group.
849+
Value can be `"none"`, `"icon"`, `"name"` or `"all"`
850+
Type: `string`, Default `"none"`
849851

850852
*nvim-tree.renderer.highlight_clipboard*
851853
Enable highlight for clipboard items using the `NvimTreeCutHL` and
@@ -879,7 +881,11 @@ Configuration options for tree indent markers.
879881
*nvim-tree.renderer.icons*
880882
Configuration options for icons.
881883

882-
Sign column icon precedence: bookmarked < git < modified < diagnostics
884+
Icon sign column precedence:
885+
diagnostics > modified > git > bookmarked
886+
887+
Left to right order:
888+
git, modified, diagnostics, bookmarked
883889

884890
*nvim-tree.renderer.icons.web_devicons*
885891
Configure optional plugin `"nvim-tree/nvim-web-devicons"`
@@ -2198,8 +2204,8 @@ Clipboard: >
21982204
Bookmark Icon: >
21992205
NvimTreeBookmark
22002206
<
2201-
Bookmark Text: >
2202-
NvimTreeBookmarkText NvimTreeBookmark
2207+
Bookmark Highlight: >
2208+
NvimTreeBookmarkHL SpellLocal
22032209
<
22042210
Picker: >
22052211
NvimTreeWindowPicker

lua/nvim-tree.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
417417
highlight_diagnostics = false,
418418
highlight_opened_files = "none",
419419
highlight_modified = "none",
420-
highlight_bookmarks = false,
420+
highlight_bookmarks = "none",
421421
highlight_clipboard = "name",
422422
indent_markers = {
423423
enable = false,
@@ -645,6 +645,8 @@ local ACCEPTED_STRINGS = {
645645
renderer = {
646646
highlight_opened_files = { "none", "icon", "name", "all" },
647647
highlight_modified = { "none", "icon", "name", "all" },
648+
highlight_bookmarks = { "none", "icon", "name", "all" },
649+
highlight_clipboard = { "none", "icon", "name", "all" },
648650
icons = {
649651
git_placement = { "before", "after", "signcolumn" },
650652
modified_placement = { "before", "after", "signcolumn" },

lua/nvim-tree/actions/fs/copy-paste.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ end
300300
function M.setup(opts)
301301
M.config.filesystem_watchers = opts.filesystem_watchers
302302
M.config.actions = opts.actions
303-
M.hl_pos = HL_POSITION[opts.renderer.highlight_clipboard]
303+
M.hl_pos = HL_POSITION[opts.renderer.highlight_clipboard] or HL_POSITION.none
304304
end
305305

306306
return M

lua/nvim-tree/colors.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ local function get_links()
112112
SignColumn = "NvimTreeNormal",
113113
CutHL = "SpellBad",
114114
CopiedHL = "SpellRare",
115+
BookmarkHL = "SpellLocal",
115116
}
116117
end
117118

lua/nvim-tree/renderer/builder.lua

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function Builder:configure_diagnostics_icon_placement(where)
8484
return self
8585
end
8686

87-
function Builder:configure_bookmarks_icon_placement(where)
87+
function Builder:configure_bookmark_icon_placement(where)
8888
if where ~= "after" and where ~= "before" and where ~= "signcolumn" then
8989
where = "before" -- default before
9090
end
@@ -256,21 +256,19 @@ end
256256

257257
---@param node table
258258
---@return HighlightedString[]|nil icon
259-
function Builder:_get_bookmarks_icon(node)
260-
local bookmarks_icon = bookmarks.get_icon(node)
261-
if bookmarks_icon and self.bookmarks_placement == "signcolumn" then
262-
table.insert(self.signs, { sign = bookmarks_icon.hl[1], lnum = self.index + 1, priority = 4 })
263-
bookmarks_icon = nil
259+
function Builder:_get_bookmark_icon(node)
260+
local bookmark_icon = bookmarks.get_icon(node)
261+
if bookmark_icon and self.bookmarks_placement == "signcolumn" then
262+
table.insert(self.signs, { sign = bookmark_icon.hl[1], lnum = self.index + 1, priority = 4 })
263+
bookmark_icon = nil
264264
end
265-
return bookmarks_icon
265+
return bookmark_icon
266266
end
267267

268268
---@param node table
269269
---@return string|nil icon_hl
270270
---@return string|nil name_hl
271271
function Builder:_get_highlight_override(node, unloaded_bufnr)
272-
-- highlights precedence:
273-
-- original < git < opened_file < modified
274272
local name_hl, icon_hl
275273

276274
-- git
@@ -331,7 +329,7 @@ end
331329
---@param git_icons HighlightedString[]|nil
332330
---@param diagnostics_icon HighlightedString|nil
333331
---@param modified_icon HighlightedString|nil
334-
---@param bookmarks_icon HighlightedString|nil
332+
---@param bookmark_icon HighlightedString|nil
335333
---@return HighlightedString[]
336334
function Builder:_format_line(
337335
indent_markers,
@@ -341,7 +339,7 @@ function Builder:_format_line(
341339
git_icons,
342340
diagnostics_icon,
343341
modified_icon,
344-
bookmarks_icon
342+
bookmark_icon
345343
)
346344
local added_len = 0
347345
local function add_to_end(t1, t2)
@@ -371,8 +369,8 @@ function Builder:_format_line(
371369
if diagnostics_icon and self.diagnostics_placement == "before" then
372370
add_to_end(line, { diagnostics_icon })
373371
end
374-
if bookmarks_icon and self.bookmarks_placement == "before" then
375-
add_to_end(line, { bookmarks_icon })
372+
if bookmark_icon and self.bookmarks_placement == "before" then
373+
add_to_end(line, { bookmark_icon })
376374
end
377375

378376
add_to_end(line, { name })
@@ -386,8 +384,8 @@ function Builder:_format_line(
386384
if diagnostics_icon and self.diagnostics_placement == "after" then
387385
add_to_end(line, { diagnostics_icon })
388386
end
389-
if bookmarks_icon and self.bookmarks_placement == "after" then
390-
add_to_end(line, { bookmarks_icon })
387+
if bookmark_icon and self.bookmarks_placement == "after" then
388+
add_to_end(line, { bookmark_icon })
391389
end
392390

393391
return line
@@ -400,8 +398,8 @@ function Builder:_build_line(node, idx, num_children, unloaded_bufnr)
400398
local indent_markers = pad.get_indent_markers(self.depth, idx, num_children, node, self.markers)
401399
local arrows = pad.get_arrows(node)
402400

403-
-- sign column precedence: bookmarks < git < modified < diagnostics
404-
local bookmarks_icon = self:_get_bookmarks_icon(node)
401+
-- adds icons to signcolumn
402+
local bookmark_icon = self:_get_bookmark_icon(node)
405403
local git_icons = self:_get_git_icons(node)
406404
local modified_icon = self:_get_modified_icon(node)
407405
local diagnostics_icon = self:_get_diagnostics_icon(node)
@@ -428,10 +426,11 @@ function Builder:_build_line(node, idx, num_children, unloaded_bufnr)
428426
end
429427

430428
-- extra highighting
429+
self:_append_highlight(node, bookmarks.get_highlight, icon.hl, name.hl)
431430
self:_append_highlight(node, diagnostics.get_highlight, icon.hl, name.hl)
432431
self:_append_highlight(node, copy_paste.get_highlight, icon.hl, name.hl)
433432

434-
local line = self:_format_line(indent_markers, arrows, icon, name, git_icons, diagnostics_icon, modified_icon)
433+
local line = self:_format_line(indent_markers, arrows, icon, name, git_icons, diagnostics_icon, modified_icon, bookmark_icon)
435434
self:_insert_line(self:_unwrap_highlighted_strings(line))
436435

437436
self.index = self.index + 1
Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
local marks = require "nvim-tree.marks"
22

3-
local M = {}
3+
local HL_POSITION = require("nvim-tree.enum").HL_POSITION
44

5-
local ICON = {}
5+
local M = {
6+
ICON = {},
7+
hl_pos = HL_POSITION.none,
8+
}
69

7-
---bookmark text highlight group if marked
10+
---Bookmark highlight group and position when highlight_bookmark.
811
---@param node table
9-
---@return string|nil group
12+
---@return HL_POSITION position none when clipboard empty
13+
---@return string|nil group only when node present in clipboard
1014
function M.get_highlight(node)
11-
if M.config.renderer.highlight_bookmarks and marks.get_mark(node) then
12-
return "NvimTreeBookmarkText"
15+
if M.hl_pos == HL_POSITION.none then
16+
return HL_POSITION.none, nil
17+
end
18+
19+
local mark = marks.get_mark(node)
20+
if mark then
21+
return M.hl_pos, "NvimTreeBookmarkHL"
22+
else
23+
return HL_POSITION.none, nil
1324
end
1425
end
1526

@@ -18,7 +29,7 @@ end
1829
---@return HighlightedString|nil bookmark icon
1930
function M.get_icon(node)
2031
if M.config.renderer.icons.show.bookmarks and marks.get_mark(node) then
21-
return ICON
32+
return M.ICON
2233
end
2334
end
2435

@@ -27,12 +38,14 @@ function M.setup(opts)
2738
renderer = opts.renderer,
2839
}
2940

30-
ICON = {
41+
M.hl_pos = HL_POSITION[opts.renderer.highlight_bookmarks] or HL_POSITION.none
42+
43+
M.ICON = {
3144
str = opts.renderer.icons.glyphs.bookmark,
3245
hl = { "NvimTreeBookmark" },
3346
}
3447

35-
vim.fn.sign_define(ICON.hl[1], { text = ICON.str, texthl = ICON.hl[1] })
48+
vim.fn.sign_define(M.ICON.hl[1], { text = M.ICON.str, texthl = M.ICON.hl[1] })
3649
end
3750

3851
return M

lua/nvim-tree/renderer/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function M.draw(unloaded_bufnr)
7474
:configure_icon_padding(M.config.icons.padding)
7575
:configure_git_icons_placement(M.config.icons.git_placement)
7676
:configure_diagnostics_icon_placement(M.config.icons.diagnostics_placement)
77-
:configure_bookmarks_icon_placement(M.config.icons.bookmarks_placement)
77+
:configure_bookmark_icon_placement(M.config.icons.bookmarks_placement)
7878
:configure_modified_placement(M.config.icons.modified_placement)
7979
:configure_symlink_destination(M.config.symlink_destination)
8080
:configure_filter(live_filter.filter, live_filter.prefix)

0 commit comments

Comments
 (0)