Skip to content

Commit

Permalink
fix(foldable_list_component): fixed issue where collapsing a folder w…
Browse files Browse the repository at this point in the history
…ould result in incorrect category count
  • Loading branch information
tanvirtin committed Jun 17, 2024
1 parent cf6d8d0 commit 02e603a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
14 changes: 7 additions & 7 deletions lua/vgit/features/screens/ProjectCommitsScreen/Store.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,20 @@ function Store:get_diff()
if err then return nil, err end
if not entry then return nil, { 'no data found' } end

local file = entry.status
if not file then return nil, { 'No file found in item' } end
local status = entry.status
if not status then return nil, { 'No file found in item' } end

local log = entry.log
if not log then return nil, { 'No log found in item' } end

local id = file.id
local filename = file.filename
local id = status.id
local filename = status.filename
local parent_hash = log.parent_hash
local commit_hash = log.commit_hash

if self.state.commits[id] then return self.state.commits[id] end

local is_deleted = file:has_either('DD')
local is_deleted = status:has_either('DD')
local reponame = git_repo.discover()
local lines_err, lines
if is_deleted then
Expand Down Expand Up @@ -184,8 +184,8 @@ function Store:get_parent_commit()
local entry, err = self:get()
if err then return nil, err end

local file = entry.status
if not file then return nil, { 'No file found in item' } end
local status = entry.status
if not status then return nil, { 'No status found in item' } end

local log = entry.log
if not log then return nil, { 'No log found in item' } end
Expand Down
21 changes: 20 additions & 1 deletion lua/vgit/ui/components/FoldableListComponent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ function FoldableListComponent:generate_lines()
local depth_0_item_counts = {}
local foldable_list_shadow = {}

local function track_closed_folder_item_count(list, depth)
if not list then return end

for i = 1, #list do
local item = list[i]

local items = item.items
if items then
track_closed_folder_item_count(items, depth + 1)
else
item_count_for_depth_0 = item_count_for_depth_0 + 1
end
end
end

local function generate_lines(list, depth)
if not list then return end

Expand Down Expand Up @@ -174,7 +189,11 @@ function FoldableListComponent:generate_lines()
},
}

if item.open then generate_lines(items, depth + 1) end
if item.open then
generate_lines(items, depth + 1)
else
track_closed_folder_item_count(items, depth + 1)
end
if depth == 0 then
depth_0_item_counts[#depth_0_item_counts + 1] = {
lnum = depth_0_lnum,
Expand Down

0 comments on commit 02e603a

Please sign in to comment.