Skip to content

Commit

Permalink
fix(#344): replace j, k with event CursorMoved
Browse files Browse the repository at this point in the history
  • Loading branch information
tanvirtin committed Apr 5, 2024
1 parent df6d0ea commit 1bdef47
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 76 deletions.
17 changes: 9 additions & 8 deletions lua/vgit/features/screens/HistoryScreen/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ function HistoryScreen:hunk_down()
return self
end

function HistoryScreen:handle_list_move(direction)
self.store:set_index(self.table_view:move(direction))
self.diff_view:render_debounced(function() self.diff_view:navigate_to_mark(1) end)
end

function HistoryScreen:show()
local buffer = Buffer(0)
local err = self.store:fetch(self.layout_type, buffer.filename)
Expand Down Expand Up @@ -106,21 +111,17 @@ function HistoryScreen:show()
{
mode = 'n',
key = 'j',
handler = loop.coroutine(function()
self.store:set_index(self.table_view:move('down'))
self.diff_view:render_debounced(function() self.diff_view:navigate_to_mark(1) end)
end),
handler = loop.coroutine(function() self:handle_list_move('down') end),
},
{
mode = 'n',
key = 'k',
handler = loop.coroutine(function()
self.store:set_index(self.table_view:move('up'))
self.diff_view:render_debounced(function() self.diff_view:navigate_to_mark(1) end)
end),
handler = loop.coroutine(function() self:handle_list_move('up') end),
},
})

self.table_view.scene:get('table').buffer:on('CursorMoved', loop.coroutine(function() self:handle_list_move() end))

return true
end

Expand Down
21 changes: 6 additions & 15 deletions lua/vgit/features/screens/ProjectCommitsScreen/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ function ProjectCommitsScreen:hunk_up() self.diff_view:prev() end

function ProjectCommitsScreen:hunk_down() self.diff_view:next() end

function ProjectCommitsScreen:handle_list_move_down()
local list_item = self.foldable_list_view:move('down')
function ProjectCommitsScreen:handle_list_move(direction)
local list_item = self.foldable_list_view:move(direction)

if not list_item then
return
Expand All @@ -70,17 +70,6 @@ function ProjectCommitsScreen:handle_list_move_down()
self.diff_view:render_debounced(loop.coroutine(function() self.diff_view:navigate_to_mark(1) end))
end

function ProjectCommitsScreen:handle_list_move_up()
local list_item = self.foldable_list_view:move('up')

if not list_item then
return
end

self.store:set_id(list_item.id)
self.diff_view:render_debounced(function() self.diff_view:navigate_to_mark(1) end)
end

function ProjectCommitsScreen:handle_on_enter()
local _, filename = self.store:get_filename()

Expand Down Expand Up @@ -176,12 +165,12 @@ function ProjectCommitsScreen:show(args)
{
mode = 'n',
key = 'j',
handler = loop.coroutine(function() self:handle_list_move_down() end),
handler = loop.coroutine(function() self:handle_list_move('down') end),
},
{
mode = 'n',
key = 'k',
handler = loop.coroutine(function() self:handle_list_move_up() end),
handler = loop.coroutine(function() self:handle_list_move('up') end),
},
{
mode = 'n',
Expand All @@ -190,6 +179,8 @@ function ProjectCommitsScreen:show(args)
},
})

self.foldable_list_view.scene:get('list').buffer:on('CursorMoved', loop.coroutine(function() self:handle_list_move() end))

local list_item = self.foldable_list_view:move_to(function(node)
local filename = node.path and node.path.file and node.path.file.filename or nil
return filename == target_filename
Expand Down
36 changes: 15 additions & 21 deletions lua/vgit/features/screens/ProjectDiffScreen/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,21 @@ function ProjectDiffScreen:make_help_bar()
return self
end

function ProjectDiffScreen:handle_list_move(direction)
local list_item = self.foldable_list_view:move(direction)

if not list_item then
return
end

self.store:set_id(list_item.id)
self.diff_view:render_debounced(function() self.diff_view:navigate_to_mark(1) end)
end

function ProjectDiffScreen:show()
loop.free_textlock()
local err, data = self.store:fetch(self.layout_type)

loop.free_textlock()
if err then
console.debug.error(err).error(err)

Expand Down Expand Up @@ -479,30 +489,12 @@ function ProjectDiffScreen:show()
{
mode = 'n',
key = 'j',
handler = loop.coroutine(function()
local list_item = self.foldable_list_view:move('down')

if not list_item then
return
end

self.store:set_id(list_item.id)
self.diff_view:render_debounced(function() self.diff_view:navigate_to_mark(1) end)
end),
handler = loop.coroutine(function() self:handle_list_move('down') end),
},
{
mode = 'n',
key = 'k',
handler = loop.coroutine(function()
local list_item = self.foldable_list_view:move('up')

if not list_item then
return
end

self.store:set_id(list_item.id)
self.diff_view:render_debounced(function() self.diff_view:navigate_to_mark(1) end)
end),
handler = loop.coroutine(function() self:handle_list_move('up') end),
},
{
mode = 'n',
Expand Down Expand Up @@ -531,6 +523,8 @@ function ProjectDiffScreen:show()
},
})

self.foldable_list_view.scene:get('list').buffer:on('CursorMoved', loop.coroutine(function() self:handle_list_move() end))

self:make_help_bar()

local list_item = self.foldable_list_view:move_to(function(node)
Expand Down
54 changes: 22 additions & 32 deletions lua/vgit/features/screens/ProjectHunksScreen/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@ function ProjectHunksScreen:hunk_down()
return self
end

function ProjectHunksScreen:handle_list_move(direction)
local list_item = self.foldable_list_view:move(direction)

if not list_item then
return
end

self.store:set_id(list_item.id)
self.diff_view:render_debounced(loop.coroutine(function()
local _, data = self.store:get_data()

if data then
self.diff_view:navigate_to_mark(data.mark_index)
end
end))
end

function ProjectHunksScreen:show(opts)
opts = opts or {}

Expand Down Expand Up @@ -133,42 +150,12 @@ function ProjectHunksScreen:show(opts)
{
mode = 'n',
key = 'j',
handler = loop.coroutine(function()
local list_item = self.foldable_list_view:move('down')

if not list_item then
return
end

self.store:set_id(list_item.id)
self.diff_view:render_debounced(loop.coroutine(function()
local _, data = self.store:get_data()

if data then
self.diff_view:navigate_to_mark(data.mark_index)
end
end))
end),
handler = loop.coroutine(function() self:handle_list_move('down') end),
},
{
mode = 'n',
key = 'k',
handler = loop.coroutine(function()
local list_item = self.foldable_list_view:move('up')

if not list_item then
return
end

self.store:set_id(list_item.id)
self.diff_view:render_debounced(loop.coroutine(function()
local _, data = self.store:get_data()

if data then
self.diff_view:navigate_to_mark(data.mark_index)
end
end))
end),
handler = loop.coroutine(function() self:handle_list_move('up') end),
},
{
mode = 'n',
Expand Down Expand Up @@ -196,6 +183,9 @@ function ProjectHunksScreen:show(opts)
end),
},
})

self.foldable_list_view.scene:get('list').buffer:on('CursorMoved', loop.coroutine(function() self:handle_list_move() end))

return true
end

Expand Down

0 comments on commit 1bdef47

Please sign in to comment.