Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1786 git next prev land on dirs #1787

Merged
merged 3 commits into from
Dec 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lua/nvim-tree/actions/moves/item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local utils = require "nvim-tree.utils"
local view = require "nvim-tree.view"
local core = require "nvim-tree.core"
local lib = require "nvim-tree.lib"
local explorer_common = require "nvim-tree.explorer.common"

local M = {}

Expand All @@ -14,7 +15,7 @@ function M.fn(where, what)
for line, node in pairs(nodes_by_line) do
local valid = false
if what == "git" then
valid = node.git_status ~= nil
valid = explorer_common.shows_git_status(node)
elseif what == "diag" then
valid = node.diag_status ~= nil
end
Expand Down
20 changes: 17 additions & 3 deletions lua/nvim-tree/explorer/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ local function get_dir_git_status(parent_ignored, status, absolute_path)
return file_status
end

if M.config.git.show_on_dirs then
return status.dirs and status.dirs[absolute_path]
end
return status.dirs and status.dirs[absolute_path]
end

local function get_git_status(parent_ignored, status, absolute_path)
Expand Down Expand Up @@ -41,6 +39,22 @@ function M.update_git_status(node, parent_ignored, status)
end
end

function M.shows_git_status(node)
if not node.git_status then
-- status doesn't exist
return false
elseif not node.nodes then
-- status exist and is a file
return true
elseif not node.open then
-- status exist, is a closed dir
return M.config.git.show_on_dirs
else
-- status exist, is a open dir
return M.config.git.show_on_dirs and M.config.git.show_on_open_dirs
end
end

function M.node_destroy(node)
if not node then
return
Expand Down
11 changes: 4 additions & 7 deletions lua/nvim-tree/renderer/components/git.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local notify = require "nvim-tree.notify"
local explorer_common = require "nvim-tree.explorer.common"

local M = {
SIGN_GROUP = "NvimTreeGitSigns",
Expand Down Expand Up @@ -75,16 +76,12 @@ local function warn_status(git_status)
)
end

local function show_git(node)
return node.git_status and (not node.open or M.git_show_on_open_dirs)
end

local function get_icons_(node)
local git_status = node.git_status
if not show_git(node) then
if not explorer_common.shows_git_status(node) then
return nil
end

local git_status = node.git_status
local icons = M.git_icons[git_status]
if not icons then
if not M.config.highlight_git then
Expand Down Expand Up @@ -141,7 +138,7 @@ end

local function get_highlight_(node)
local git_status = node.git_status
if not show_git(node) then
if not explorer_common.shows_git_status(node) then
return
end

Expand Down