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

screens | replace j, k with event CursorMoved #357

Merged
merged 1 commit into from
Apr 5, 2024
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
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
Loading