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
This commit is contained in:
Alexander Courtis
2023-09-24 15:07:02 +10:00
committed by GitHub
parent ea147418e0
commit d49a284236
8 changed files with 156 additions and 60 deletions

View File

@@ -1,6 +1,4 @@
local view = require "nvim-tree.view"
local Iterator = require "nvim-tree.iterators.node-iterator"
local core = require "nvim-tree.core"
local renderer = {} -- circular dependency
local NvimTreeMarks = {}
@@ -8,12 +6,14 @@ local M = {}
local function add_mark(node)
NvimTreeMarks[node.absolute_path] = node
M.draw()
renderer.draw()
end
local function remove_mark(node)
NvimTreeMarks[node.absolute_path] = nil
M.draw()
renderer.draw()
end
function M.toggle_mark(node)
@@ -26,11 +26,14 @@ function M.toggle_mark(node)
else
add_mark(node)
end
renderer.draw()
end
function M.clear_marks()
NvimTreeMarks = {}
M.draw()
renderer.draw()
end
function M.get_mark(node)
@@ -45,36 +48,9 @@ function M.get_marks()
return list
end
local GROUP = "NvimTreeMarkSigns"
local SIGN_NAME = "NvimTreeMark"
function M.clear()
vim.fn.sign_unplace(GROUP)
end
function M.draw()
if not view.is_visible() then
return
end
M.clear()
local buf = view.get_bufnr()
local add = core.get_nodes_starting_line() - 1
Iterator.builder(core.get_explorer().nodes)
:recursor(function(node)
return node.group_next and { node.group_next } or (node.open and node.nodes)
end)
:applier(function(node, idx)
if M.get_mark(node) then
vim.fn.sign_place(0, GROUP, SIGN_NAME, buf, { lnum = idx + add, priority = 3 })
end
end)
:iterate()
end
function M.setup(opts)
vim.fn.sign_define(SIGN_NAME, { text = opts.renderer.icons.glyphs.bookmark, texthl = "NvimTreeBookmark" })
renderer = require "nvim-tree.renderer"
require("nvim-tree.marks.bulk-delete").setup(opts)
require("nvim-tree.marks.bulk-trash").setup(opts)
require("nvim-tree.marks.bulk-move").setup(opts)