refactor(marks): fix offset line and move into init.lua

also set node in marks record instead of true
This commit is contained in:
kiyan 2022-07-12 09:34:26 +02:00
parent 078a9e5bf9
commit 6a49a0301f
2 changed files with 6 additions and 5 deletions

View File

@ -1262,6 +1262,6 @@ You can toggle marks on files/folders with
default.
To get the list of marked paths, you can call
`require("nvim-tree.marks").get_marks()`. This will return `{string}`.
`require("nvim-tree.marks").get_marks()`. This will return `{node}`.
vim:tw=78:ts=4:sw=4:et:ft=help:norl:

View File

@ -7,7 +7,7 @@ local NvimTreeMarks = {}
local M = {}
local function add_mark(node)
NvimTreeMarks[node.absolute_path] = true
NvimTreeMarks[node.absolute_path] = node
M.draw()
end
@ -30,8 +30,8 @@ end
function M.get_marks()
local list = {}
for k in pairs(NvimTreeMarks) do
table.insert(list, k)
for _, node in pairs(NvimTreeMarks) do
table.insert(list, node)
end
return list
end
@ -51,13 +51,14 @@ function M.draw()
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.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 + 1, priority = 3 })
vim.fn.sign_place(0, GROUP, SIGN_NAME, buf, { lnum = idx + add, priority = 3 })
end
end)
:iterate()