Skip to content

Commit

Permalink
fix: select hunk gets all adjacent linematch hunks
Browse files Browse the repository at this point in the history
Fixes #1133
  • Loading branch information
lewis6991 committed Jan 20, 2025
1 parent 8b74e56 commit abc6dec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 7 additions & 1 deletion doc/gitsigns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,15 @@ get_hunks({bufnr}) *gitsigns.get_hunks()*
`"start"`: Line number (1-based)
`"count"`: Line count

select_hunk() *gitsigns.select_hunk()*
select_hunk({opts}) *gitsigns.select_hunk()*
Select the hunk under the cursor.

Parameters: ~
{opts} (table|nil): Additional options:
{greedy}: (boolean)
Select all contiguous hunks. Only useful if 'diff_opts'
contains `linematch`. Defaults to `true`.

preview_hunk_inline() *gitsigns.preview_hunk_inline()*
Preview the hunk at the cursor position inline in the buffer.

Expand Down
11 changes: 9 additions & 2 deletions lua/gitsigns/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -913,8 +913,15 @@ M.preview_hunk_inline = async.create(function()
end)

--- Select the hunk under the cursor.
M.select_hunk = function()
local hunk = get_cursor_hunk()
---
--- @param opts table|nil Additional options:
--- • {greedy}: (boolean)
--- Select all contiguous hunks. Only useful if 'diff_opts'
--- contains `linematch`. Defaults to `true`.
M.select_hunk = function(opts)
local bufnr = current_buf()
opts = opts or {}
local hunk = get_hunk(bufnr, nil, opts.greedy ~= false)
if not hunk then
return
end
Expand Down

0 comments on commit abc6dec

Please sign in to comment.