From abc6dec92232944108250e321858014bf79de245 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 20 Jan 2025 11:09:08 +0000 Subject: [PATCH] fix: select hunk gets all adjacent linematch hunks Fixes #1133 --- doc/gitsigns.txt | 8 +++++++- lua/gitsigns/actions.lua | 11 +++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/doc/gitsigns.txt b/doc/gitsigns.txt index f325cdb1d..a1e9ce7f4 100644 --- a/doc/gitsigns.txt +++ b/doc/gitsigns.txt @@ -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. diff --git a/lua/gitsigns/actions.lua b/lua/gitsigns/actions.lua index f29677e71..f14a78a35 100644 --- a/lua/gitsigns/actions.lua +++ b/lua/gitsigns/actions.lua @@ -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