Skip to content

Commit

Permalink
Merge pull request #10 from benlubas/push-wtzzowwlroyl
Browse files Browse the repository at this point in the history
fix: visual add lines
  • Loading branch information
julienvincent authored Jul 28, 2024
2 parents 3431f24 + 528e792 commit 1f2f4dc
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions lua/hunk/ui/file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,34 @@ 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()
vim.cmd("normal! <Esc>")
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("<esc>", 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

vim.schedule(function()
params.on_event({
type = "toggle-lines",
lines = lines,
file = File,
})
end)
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-lines",
lines = lines,
type = "toggle-hunk",
line = vim.api.nvim_win_get_cursor(window)[1],
file = File,
})
end, { buffer = buf })
Expand Down

0 comments on commit 1f2f4dc

Please sign in to comment.