Skip to content

Commit 1ee1d07

Browse files
committed
add BaseNode:is
1 parent 7b46a16 commit 1ee1d07

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

lua/nvim-tree/marks/init.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ local rename_file = require("nvim-tree.actions.fs.rename-file")
88
local trash = require("nvim-tree.actions.fs.trash")
99
local utils = require("nvim-tree.utils")
1010

11+
local DirectoryNode = require "nvim-tree.node.directory"
12+
1113
---@class Marks
1214
---@field config table hydrated user opts.filters
1315
---@field private explorer Explorer
@@ -152,7 +154,7 @@ function Marks:bulk_move()
152154
local node_at_cursor = lib.get_node_at_cursor()
153155
local default_path = core.get_cwd()
154156

155-
if node_at_cursor and node_at_cursor.type == "directory" then
157+
if node_at_cursor and node_at_cursor:is(DirectoryNode) then
156158
default_path = node_at_cursor.absolute_path
157159
elseif node_at_cursor and node_at_cursor.parent then
158160
default_path = node_at_cursor.parent.absolute_path

lua/nvim-tree/node/factory.lua

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ local Watcher = require("nvim-tree.watcher")
55

66
local M = {}
77

8+
--- TODO merge #2922 and pass just stat, as stat.type from lstat is correct
9+
810
---Factory function to create the appropriate Node
911
---@param explorer Explorer
1012
---@param parent Node

lua/nvim-tree/node/init.lua

+17
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,23 @@ function BaseNode:destroy()
3838
end
3939
end
4040

41+
---From plenary
42+
---Checks if the object is an instance
43+
---This will start with the lowest class and loop over all the superclasses.
44+
---@param self BaseNode
45+
---@param T BaseNode
46+
---@return boolean
47+
function BaseNode:is(T)
48+
local mt = getmetatable(self)
49+
while mt do
50+
if mt == T then
51+
return true
52+
end
53+
mt = getmetatable(mt)
54+
end
55+
return false
56+
end
57+
4158
---@return boolean
4259
function BaseNode:has_one_child_folder()
4360
return #self.nodes == 1 and self.nodes[1].nodes and vim.loop.fs_access(self.nodes[1].absolute_path, "R") or false

0 commit comments

Comments
 (0)