Skip to content

Commit 9d9c571

Browse files
1786 git next prev land on dirs (#1787)
* Filtered dir with git status that are open when show_on_open_dir is false * refactored for single source of truth of existence of git status on a node Putting `has_git_status()` in `explorer.common` because that's where node.status is constructed Or at least I think that's where it's constructed * 1786 semantic nit Co-authored-by: Alexander Courtis <alex@courtis.org>
1 parent 07149da commit 9d9c571

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

lua/nvim-tree/actions/moves/item.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ local utils = require "nvim-tree.utils"
22
local view = require "nvim-tree.view"
33
local core = require "nvim-tree.core"
44
local lib = require "nvim-tree.lib"
5+
local explorer_common = require "nvim-tree.explorer.common"
56

67
local M = {}
78

@@ -14,7 +15,7 @@ function M.fn(where, what)
1415
for line, node in pairs(nodes_by_line) do
1516
local valid = false
1617
if what == "git" then
17-
valid = node.git_status ~= nil
18+
valid = explorer_common.shows_git_status(node)
1819
elseif what == "diag" then
1920
valid = node.diag_status ~= nil
2021
end

lua/nvim-tree/explorer/common.lua

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ local function get_dir_git_status(parent_ignored, status, absolute_path)
1010
return file_status
1111
end
1212

13-
if M.config.git.show_on_dirs then
14-
return status.dirs and status.dirs[absolute_path]
15-
end
13+
return status.dirs and status.dirs[absolute_path]
1614
end
1715

1816
local function get_git_status(parent_ignored, status, absolute_path)
@@ -41,6 +39,22 @@ function M.update_git_status(node, parent_ignored, status)
4139
end
4240
end
4341

42+
function M.shows_git_status(node)
43+
if not node.git_status then
44+
-- status doesn't exist
45+
return false
46+
elseif not node.nodes then
47+
-- status exist and is a file
48+
return true
49+
elseif not node.open then
50+
-- status exist, is a closed dir
51+
return M.config.git.show_on_dirs
52+
else
53+
-- status exist, is a open dir
54+
return M.config.git.show_on_dirs and M.config.git.show_on_open_dirs
55+
end
56+
end
57+
4458
function M.node_destroy(node)
4559
if not node then
4660
return

lua/nvim-tree/renderer/components/git.lua

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local notify = require "nvim-tree.notify"
2+
local explorer_common = require "nvim-tree.explorer.common"
23

34
local M = {
45
SIGN_GROUP = "NvimTreeGitSigns",
@@ -75,16 +76,12 @@ local function warn_status(git_status)
7576
)
7677
end
7778

78-
local function show_git(node)
79-
return node.git_status and (not node.open or M.git_show_on_open_dirs)
80-
end
81-
8279
local function get_icons_(node)
83-
local git_status = node.git_status
84-
if not show_git(node) then
80+
if not explorer_common.shows_git_status(node) then
8581
return nil
8682
end
8783

84+
local git_status = node.git_status
8885
local icons = M.git_icons[git_status]
8986
if not icons then
9087
if not M.config.highlight_git then
@@ -141,7 +138,7 @@ end
141138

142139
local function get_highlight_(node)
143140
local git_status = node.git_status
144-
if not show_git(node) then
141+
if not explorer_common.shows_git_status(node) then
145142
return
146143
end
147144

0 commit comments

Comments
 (0)