From 6286fb9fc240bb8b680ec86468f704e0b3ed6d4e Mon Sep 17 00:00:00 2001 From: Ben Lubas Date: Sun, 28 Jul 2024 10:44:32 -0400 Subject: [PATCH 1/2] fix: visual add lines --- lua/hunk/ui/file.lua | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lua/hunk/ui/file.lua b/lua/hunk/ui/file.lua index 12dc909..af6839c 100644 --- a/lua/hunk/ui/file.lua +++ b/lua/hunk/ui/file.lua @@ -47,21 +47,24 @@ function M.create(window, params) end, { buffer = buf }) vim.keymap.set("v", chord, function() - vim.cmd("normal! ") + local start_line = vim.fn.getpos(".")[2] + local end_line = vim.fn.getpos("v")[2] - local start_line = vim.fn.getpos("'<")[2] - local end_line = vim.fn.getpos("'>")[2] + -- escape out of visual mode + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("", true, false, true), "m", false) local lines = {} - for i = start_line, start_line + end_line do + for i = math.min(start_line, end_line), math.max(start_line, end_line) do table.insert(lines, i) end - params.on_event({ - type = "toggle-lines", - lines = lines, - file = File, - }) + vim.schedule(function() + params.on_event({ + type = "toggle-lines", + lines = lines, + file = File, + }) + end) end, { buffer = buf }) end From 528e79216ded6c27ab0ae2d2c631f2b20ebbb52e Mon Sep 17 00:00:00 2001 From: Ben Lubas Date: Sun, 28 Jul 2024 11:46:06 -0400 Subject: [PATCH 2/2] fix: use toggle line key for visual toggle line --- lua/hunk/ui/file.lua | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lua/hunk/ui/file.lua b/lua/hunk/ui/file.lua index af6839c..ffc05fe 100644 --- a/lua/hunk/ui/file.lua +++ b/lua/hunk/ui/file.lua @@ -35,16 +35,6 @@ function M.create(window, params) file = File, }) end, { buffer = buf }) - end - - for _, chord in ipairs(utils.into_table(config.keys.diff.toggle_hunk)) do - vim.keymap.set("n", chord, function() - params.on_event({ - type = "toggle-hunk", - line = vim.api.nvim_win_get_cursor(window)[1], - file = File, - }) - end, { buffer = buf }) vim.keymap.set("v", chord, function() local start_line = vim.fn.getpos(".")[2] @@ -68,6 +58,16 @@ function M.create(window, params) end, { buffer = buf }) end + for _, chord in ipairs(utils.into_table(config.keys.diff.toggle_hunk)) do + vim.keymap.set("n", chord, function() + params.on_event({ + type = "toggle-hunk", + line = vim.api.nvim_win_get_cursor(window)[1], + file = File, + }) + end, { buffer = buf }) + end + local function apply_signs() api.signs.clear_signs(buf)