Skip to content

Commit d49a284

Browse files
authored
feat(#2411): add renderer.highlight_bookmarks, renderer.icons.bookmarks_placement (#2412)
* feat(#1079): add highlight NvimTreeCopiedText and NvimTreeCutText * feat(#1079): add highlight NvimTreeCopiedText and NvimTreeCutText * feat(#1079): node may not be present in copy and cut * feat(#2411): bookmark highlight and icon placement * feat(#1079): add renderer.highlight_clipboard * feat(#1079): add renderer.highlight_clipboard * feat(#2411): bookmark highlight and icon placement * feat(#2411): bookmark highlight and icon placement * style * feat(#2411): bookmark highlight and icon placement * feat(#2411): bookmark highlight and icon placement * feat(#2411): bookmark highlight and icon placement * feat(#2411): bookmark highlight and icon placement
1 parent ea14741 commit d49a284

File tree

8 files changed

+156
-60
lines changed

8 files changed

+156
-60
lines changed

doc/nvim-tree-lua.txt

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +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 = "none",
391392
highlight_clipboard = "name",
392393
indent_markers = {
393394
enable = false,
@@ -412,17 +413,19 @@ Following is the default configuration. See |nvim-tree-opts| for details.
412413
},
413414
},
414415
git_placement = "before",
415-
diagnostics_placement = "signcolumn",
416416
modified_placement = "after",
417+
diagnostics_placement = "signcolumn",
418+
bookmarks_placement = "signcolumn",
417419
padding = " ",
418420
symlink_arrow = " ➛ ",
419421
show = {
420422
file = true,
421423
folder = true,
422424
folder_arrow = true,
423425
git = true,
424-
diagnostics = true,
425426
modified = true,
427+
diagnostics = true,
428+
bookmarks = true,
426429
},
427430
glyphs = {
428431
default = "",
@@ -777,7 +780,8 @@ Use nvim-tree in a floating window.
777780
==============================================================================
778781
5.3 OPTS: RENDERER *nvim-tree-opts-renderer*
779782

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

782786
*nvim-tree.renderer.add_trailing*
783787
Appends a trailing slash to folder names.
@@ -819,20 +823,17 @@ Whether to show the destination of the symlink.
819823
*nvim-tree.renderer.highlight_git*
820824
Enable highlight for git attributes using `NvimTreeGit*` highlight groups.
821825
Requires |nvim-tree.git.enable|
822-
This can be used with or without the icons.
823826
Type: `boolean`, Default: `false`
824827

825828
*nvim-tree.renderer.highlight_diagnostics*
826829
Enable highlight for diagnostics using `LspDiagnosticsError*Text` highlight groups.
827830
Requires |nvim-tree.diagnostics.enable|
828-
This can be used with or without the icons.
829831
Type: `boolean`, Default: `false`
830832

831833
*nvim-tree.renderer.highlight_opened_files*
832834
Highlight icons and/or names for |bufloaded()| files using the
833835
`NvimTreeOpenedFile` highlight group.
834-
See |nvim-tree-api.navigate.opened.next()| and
835-
|nvim-tree-api.navigate.opened.prev()|
836+
See |nvim-tree-api.navigate.opened.next()| and |nvim-tree-api.navigate.opened.prev()|
836837
Value can be `"none"`, `"icon"`, `"name"` or `"all"`.
837838
Type: `string`, Default: `"none"`
838839

@@ -841,7 +842,11 @@ Highlight icons and/or names for modified files using the
841842
`NvimTreeModifiedFile` highlight group.
842843
Requires |nvim-tree.modified.enable|
843844
Value can be `"none"`, `"icon"`, `"name"` or `"all"`
844-
This can be used with or without the icons.
845+
Type: `string`, Default `"none"`
846+
847+
*nvim-tree.renderer.highlight_bookmarks*
848+
Highlight bookmarked using the `NvimTreeBookmarkHL` group.
849+
Value can be `"none"`, `"icon"`, `"name"` or `"all"`
845850
Type: `string`, Default `"none"`
846851

847852
*nvim-tree.renderer.highlight_clipboard*
@@ -876,7 +881,8 @@ Configuration options for tree indent markers.
876881
*nvim-tree.renderer.icons*
877882
Configuration options for icons.
878883

879-
Sign column icon precedence: git < modified < diagnostics
884+
Icon sign column precedence:
885+
diagnostics > modified > git > bookmarked
880886

881887
*nvim-tree.renderer.icons.web_devicons*
882888
Configure optional plugin `"nvim-tree/nvim-web-devicons"`
@@ -923,6 +929,12 @@ Sign column icon precedence: git < modified < diagnostics
923929
or `"signcolumn"` (requires |nvim-tree.view.signcolumn| enabled).
924930
Type: `string`, Default: `"after"`
925931

932+
*nvim-tree.renderer.icons.bookmarks_placement*
933+
Place where the bookmarks icon will be rendered.
934+
Can be `"after"` or `"before"` filename (after the file/folders icons)
935+
or `"signcolumn"` (requires |nvim-tree.view.signcolumn| enabled).
936+
Type: `string`, Default: `signcolumn`
937+
926938
*nvim-tree.renderer.icons.padding*
927939
Inserted between icon and filename.
928940
Type: `string`, Default: `" "`
@@ -933,6 +945,7 @@ Sign column icon precedence: git < modified < diagnostics
933945

934946
*nvim-tree.renderer.icons.show*
935947
Configuration options for showing icon types.
948+
Left to right order: file/folder, git, modified, diagnostics, bookmarked.
936949

937950
*nvim-tree.renderer.icons.show.file*
938951
Show an icon before the file name.
@@ -952,14 +965,18 @@ Sign column icon precedence: git < modified < diagnostics
952965
Requires |git.enable| `= true`
953966
Type: `boolean`, Default: `true`
954967

968+
*nvim-tree.renderer.icons.show.modified*
969+
Show a modified icon, see |renderer.icons.modified_placement|
970+
Requires |modified.enable| `= true`
971+
Type: `boolean`, Default: `true`
972+
955973
*nvim-tree.renderer.icons.show.diagnostics*
956974
Show a diagnostics status icon, see |renderer.icons.diagnostics_placement|
957975
Requires |diagnostics.enable| `= true`
958976
Type: `boolean`, Default: `true`
959977

960-
*nvim-tree.renderer.icons.show.modified*
961-
Show a modified icon, see |renderer.icons.modified_placement|
962-
Requires |modified.enable| `= true`
978+
*nvim-tree.renderer.icons.show.bookmarks*
979+
Show a bookmark icon, see |renderer.icons.bookmarks_placement|
963980
Type: `boolean`, Default: `true`
964981

965982
*nvim-tree.renderer.icons.glyphs*
@@ -2153,7 +2170,6 @@ Icon: >
21532170
NvimTreeFolderIcon
21542171
NvimTreeOpenedFolderIcon NvimTreeFolderIcon
21552172
NvimTreeClosedFolderIcon NvimTreeFolderIcon
2156-
NvimTreeBookmark
21572173
NvimTreeFolderArrowClosed NvimTreeIndentMarker
21582174
NvimTreeFolderArrowOpen NvimTreeIndentMarker
21592175
<
@@ -2182,6 +2198,12 @@ Clipboard: >
21822198
NvimTreeCopiedHL SpellRare
21832199
NvimTreeCutHL SpellBad
21842200
<
2201+
Bookmark Icon: >
2202+
NvimTreeBookmark
2203+
<
2204+
Bookmark Highlight: >
2205+
NvimTreeBookmarkHL SpellLocal
2206+
<
21852207
Picker: >
21862208
NvimTreeWindowPicker
21872209
<

lua/nvim-tree.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
417417
highlight_diagnostics = false,
418418
highlight_opened_files = "none",
419419
highlight_modified = "none",
420+
highlight_bookmarks = "none",
420421
highlight_clipboard = "name",
421422
indent_markers = {
422423
enable = false,
@@ -441,17 +442,19 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
441442
},
442443
},
443444
git_placement = "before",
444-
diagnostics_placement = "signcolumn",
445445
modified_placement = "after",
446+
diagnostics_placement = "signcolumn",
447+
bookmarks_placement = "signcolumn",
446448
padding = " ",
447449
symlink_arrow = "",
448450
show = {
449451
file = true,
450452
folder = true,
451453
folder_arrow = true,
452454
git = true,
453-
diagnostics = true,
454455
modified = true,
456+
diagnostics = true,
457+
bookmarks = true,
455458
},
456459
glyphs = {
457460
default = "",
@@ -659,10 +662,13 @@ local ACCEPTED_STRINGS = {
659662
renderer = {
660663
highlight_opened_files = { "none", "icon", "name", "all" },
661664
highlight_modified = { "none", "icon", "name", "all" },
665+
highlight_bookmarks = { "none", "icon", "name", "all" },
666+
highlight_clipboard = { "none", "icon", "name", "all" },
662667
icons = {
663668
git_placement = { "before", "after", "signcolumn" },
664-
diagnostics_placement = { "before", "after", "signcolumn" },
665669
modified_placement = { "before", "after", "signcolumn" },
670+
diagnostics_placement = { "before", "after", "signcolumn" },
671+
bookmarks_placement = { "before", "after", "signcolumn" },
666672
},
667673
},
668674
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local core = require "nvim-tree.core"
55
local events = require "nvim-tree.events"
66
local notify = require "nvim-tree.notify"
77
local renderer = require "nvim-tree.renderer"
8+
local reloaders = require "nvim-tree.actions.reloaders.reloaders"
89

910
local HL_POSITION = require("nvim-tree.enum").HL_POSITION
1011

@@ -195,7 +196,7 @@ local function do_paste(node, action_type, action_fn)
195196

196197
clipboard[action_type] = {}
197198
if not M.config.filesystem_watchers.enable then
198-
return require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
199+
return reloaders.reload_explorer()
199200
end
200201
end
201202

@@ -300,7 +301,7 @@ end
300301
function M.setup(opts)
301302
M.config.filesystem_watchers = opts.filesystem_watchers
302303
M.config.actions = opts.actions
303-
M.hl_pos = HL_POSITION[opts.renderer.highlight_clipboard]
304+
M.hl_pos = HL_POSITION[opts.renderer.highlight_clipboard] or HL_POSITION.none
304305
end
305306

306307
return M

lua/nvim-tree/colors.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ local function get_links()
108108
SignColumn = "NvimTreeNormal",
109109
CutHL = "SpellBad",
110110
CopiedHL = "SpellRare",
111+
BookmarkHL = "SpellLocal",
111112
}
112113
end
113114

lua/nvim-tree/marks/init.lua

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
local view = require "nvim-tree.view"
2-
local Iterator = require "nvim-tree.iterators.node-iterator"
3-
local core = require "nvim-tree.core"
1+
local renderer = {} -- circular dependency
42

53
local NvimTreeMarks = {}
64

75
local M = {}
86

97
local function add_mark(node)
108
NvimTreeMarks[node.absolute_path] = node
11-
M.draw()
9+
10+
renderer.draw()
1211
end
1312

1413
local function remove_mark(node)
1514
NvimTreeMarks[node.absolute_path] = nil
16-
M.draw()
15+
16+
renderer.draw()
1717
end
1818

1919
function M.toggle_mark(node)
@@ -26,11 +26,14 @@ function M.toggle_mark(node)
2626
else
2727
add_mark(node)
2828
end
29+
30+
renderer.draw()
2931
end
3032

3133
function M.clear_marks()
3234
NvimTreeMarks = {}
33-
M.draw()
35+
36+
renderer.draw()
3437
end
3538

3639
function M.get_mark(node)
@@ -45,36 +48,9 @@ function M.get_marks()
4548
return list
4649
end
4750

48-
local GROUP = "NvimTreeMarkSigns"
49-
local SIGN_NAME = "NvimTreeMark"
50-
51-
function M.clear()
52-
vim.fn.sign_unplace(GROUP)
53-
end
54-
55-
function M.draw()
56-
if not view.is_visible() then
57-
return
58-
end
59-
60-
M.clear()
61-
62-
local buf = view.get_bufnr()
63-
local add = core.get_nodes_starting_line() - 1
64-
Iterator.builder(core.get_explorer().nodes)
65-
:recursor(function(node)
66-
return node.group_next and { node.group_next } or (node.open and node.nodes)
67-
end)
68-
:applier(function(node, idx)
69-
if M.get_mark(node) then
70-
vim.fn.sign_place(0, GROUP, SIGN_NAME, buf, { lnum = idx + add, priority = 3 })
71-
end
72-
end)
73-
:iterate()
74-
end
75-
7651
function M.setup(opts)
77-
vim.fn.sign_define(SIGN_NAME, { text = opts.renderer.icons.glyphs.bookmark, texthl = "NvimTreeBookmark" })
52+
renderer = require "nvim-tree.renderer"
53+
7854
require("nvim-tree.marks.bulk-delete").setup(opts)
7955
require("nvim-tree.marks.bulk-trash").setup(opts)
8056
require("nvim-tree.marks.bulk-move").setup(opts)

0 commit comments

Comments
 (0)