-
-
Notifications
You must be signed in to change notification settings - Fork 611
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
refactor(#2380): multi instance nvim-tree.marks
- Loading branch information
1 parent
48a9290
commit 4e396b2
Showing
9 changed files
with
135 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,78 @@ | ||
local renderer = {} -- circular dependency | ||
|
||
local NvimTreeMarks = {} | ||
---@class Marks | ||
---@field private marks Node[] | ||
local Marks = {} | ||
|
||
local M = {} | ||
---@return Marks | ||
function Marks:new() | ||
local o = {} | ||
setmetatable(o, self) | ||
self.__index = self | ||
|
||
---@class MinimalNode | ||
---@field absolute_path string | ||
o.marks = {} | ||
|
||
---@param node Node|MinimalNode | ||
local function add_mark(node) | ||
NvimTreeMarks[node.absolute_path] = node | ||
return o | ||
end | ||
|
||
---@private | ||
---@param node Node | ||
function Marks:add_mark(node) | ||
self.marks[node.absolute_path] = node | ||
|
||
renderer.draw() | ||
end | ||
|
||
---@param node Node|MinimalNode | ||
local function remove_mark(node) | ||
NvimTreeMarks[node.absolute_path] = nil | ||
---@private | ||
---@param node Node | ||
function Marks:remove_mark(node) | ||
self.marks[node.absolute_path] = nil | ||
|
||
renderer.draw() | ||
end | ||
|
||
---@param node Node|MinimalNode | ||
function M.toggle_mark(node) | ||
---@param node Node | ||
function Marks:toggle_mark(node) | ||
if node.absolute_path == nil then | ||
return | ||
end | ||
|
||
if M.get_mark(node) then | ||
remove_mark(node) | ||
if self:get_mark(node) then | ||
self:remove_mark(node) | ||
else | ||
add_mark(node) | ||
self:add_mark(node) | ||
end | ||
|
||
renderer.draw() | ||
end | ||
|
||
function M.clear_marks() | ||
NvimTreeMarks = {} | ||
function Marks:clear_marks() | ||
self.marks = {} | ||
|
||
renderer.draw() | ||
end | ||
|
||
---@param node Node|MinimalNode | ||
---@return table|nil | ||
function M.get_mark(node) | ||
return node and NvimTreeMarks[node.absolute_path] | ||
---@param node Node | ||
---@return Node|nil | ||
function Marks:get_mark(node) | ||
return node and self.marks[node.absolute_path] | ||
end | ||
|
||
---@return table | ||
function M.get_marks() | ||
---@return Node[] | ||
function Marks:get_marks() | ||
local list = {} | ||
for _, node in pairs(NvimTreeMarks) do | ||
for _, node in pairs(self.marks) do | ||
table.insert(list, node) | ||
end | ||
return list | ||
end | ||
|
||
function M.setup(opts) | ||
function Marks.setup(opts) | ||
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) | ||
end | ||
|
||
return M | ||
return Marks |
Oops, something went wrong.