Skip to content

Commit

Permalink
fix(project_diff_screen): fix rendering and navigation issues when op…
Browse files Browse the repository at this point in the history
…ened on subdirectory
  • Loading branch information
tanvirtin committed Jul 11, 2024
1 parent 90723e8 commit cfd4e0f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
23 changes: 17 additions & 6 deletions lua/vgit/features/screens/ProjectDiffScreen/Store.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function Store:constructor()
state = {
lnum = 1,
diffs = {},
reponame = nil,
mark_index = 1,
list_folds = {},
list_entries = {},
Expand All @@ -34,6 +35,7 @@ function Store:reset()
self.data = nil
self.state = {
diffs = {},
reponame = nil,
mark_index = 1,
list_entries = {},
}
Expand Down Expand Up @@ -111,6 +113,7 @@ function Store:fetch(shape, opts)

self.shape = shape
self.data = data
self.state.reponame = reponame

return self.data
end
Expand All @@ -136,6 +139,16 @@ function Store:get_filename()
return entry.status.filename
end

function Store:get_filepath()
local reponame = self.state.reponame
local filename = self:get_filename()

filename = fs.make_relative(reponame, filename)
filename = string.format('%s/%s', reponame, filename)

return filename
end

function Store:get_filetype()
local entry, err = self:get()
if err then return nil, err end
Expand All @@ -161,13 +174,12 @@ function Store:set_list_folds(list_folds)
end

function Store:conflict_status()
local reponame = git_repo.discover()
return git_conflict.status(reponame)
return git_conflict.status(self.state.reponame)
end

function Store:get_lines(status, type)
local filename = status.filename
local reponame = git_repo.discover()
local reponame = self.state.reponame

if type == 'unmerged' then
if status:has_both('UD') then return git_show.lines(reponame, filename, ':2') end
Expand All @@ -180,13 +192,12 @@ function Store:get_lines(status, type)
if status:has('D ') then return git_show.lines(reponame, filename, 'HEAD') end
if type == 'staged' or status:has(' D') then return git_show.lines(reponame, filename) end

loop.free_textlock()
return fs.read_file(filename)
return fs.read_file(self:get_filepath())
end

function Store:get_hunks(status, type, lines)
local filename = status.filename
local reponame = git_repo.discover()
local reponame = self.state.reponame

if type == 'unmerged' then
if status:has_both('UD') then return git_hunks.custom(lines, { deleted = true }) end
Expand Down
11 changes: 7 additions & 4 deletions lua/vgit/features/screens/ProjectDiffScreen/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,13 @@ function ProjectDiffScreen:show()
local mark, _ = self.diff_view:get_current_mark_under_cursor()
if not mark then return end

local filename = self.store:get_filename()
if not filename then return end
local filepath = self.store:get_filepath()
loop.free_textlock()
if not filepath then return end

self:destroy()

fs.open(filename)
fs.open(filepath)

Window(0):set_lnum(mark.top_relative):position_cursor('center')
end),
Expand Down Expand Up @@ -479,7 +480,9 @@ function ProjectDiffScreen:show()
key = '<enter>',
handler = loop.coroutine(function()
local mark, _ = self.diff_view:get_current_mark_under_cursor()
local filename = self.store:get_filename()
local filename = self.store:get_filepath()
loop.free_textlock()

if not filename then
self.foldable_list_view:toggle_current_list_item()
self.foldable_list_view:render()
Expand Down

0 comments on commit cfd4e0f

Please sign in to comment.