@@ -149,9 +149,10 @@ M.toggle_deleted = function(value)
149
149
return config .show_deleted
150
150
end
151
151
152
- --- @param bufnr ? integer
153
- --- @param hunks ? Gitsigns.Hunk.Hunk[] ?
154
- --- @return Gitsigns.Hunk.Hunk ?
152
+ --- @param bufnr ? integer
153
+ --- @param hunks ? Gitsigns.Hunk.Hunk[] ?
154
+ --- @return Gitsigns.Hunk.Hunk ? hunk
155
+ --- @return integer ? index
155
156
local function get_cursor_hunk (bufnr , hunks )
156
157
bufnr = bufnr or current_buf ()
157
158
@@ -185,13 +186,14 @@ local function get_range(params)
185
186
return range
186
187
end
187
188
189
+ --- @async
188
190
--- @param bufnr integer
189
191
--- @param bcache Gitsigns.CacheEntry
190
192
--- @param greedy ? boolean
191
193
--- @param staged ? boolean
192
194
--- @return Gitsigns.Hunk.Hunk[] ? hunks
193
195
local function get_hunks (bufnr , bcache , greedy , staged )
194
- if greedy then
196
+ if greedy and config . diff_opts . linematch then
195
197
-- Re-run the diff without linematch
196
198
local buftext = util .buf_lines (bufnr )
197
199
local text --- @type string[] ?
@@ -225,7 +227,8 @@ local function get_hunk(bufnr, range, greedy, staged)
225
227
local hunks = get_hunks (bufnr , bcache , greedy , staged )
226
228
227
229
if not range then
228
- return get_cursor_hunk (bufnr , hunks )
230
+ local hunk = get_cursor_hunk (bufnr , hunks )
231
+ return hunk
229
232
end
230
233
231
234
table.sort (range )
298
301
--- @param bufnr integer
299
302
--- @param hunk Gitsigns.Hunk.Hunk
300
303
local function reset_hunk (bufnr , hunk )
301
- local lstart , lend --- @type integer , integer
304
+ local lstart , lend --- @type integer , integer
302
305
if hunk .type == ' delete' then
303
306
lstart = hunk .added .start
304
307
lend = hunk .added .start
@@ -732,23 +735,39 @@ local function feedkeys(keys)
732
735
api .nvim_feedkeys (cy , ' n' , false )
733
736
end
734
737
738
+ --- @param bufnr integer
739
+ --- @param greedy ? boolean
740
+ --- @return Gitsigns.Hunk.Hunk ? hunk
741
+ --- @return boolean ? staged
742
+ local function get_hunk_with_staged (bufnr , greedy )
743
+ local hunk = get_hunk (bufnr , nil , greedy , false )
744
+ if hunk then
745
+ return hunk , false
746
+ end
747
+
748
+ hunk = get_hunk (bufnr , nil , greedy , true )
749
+ if hunk then
750
+ return hunk , true
751
+ end
752
+ end
753
+
735
754
--- Preview the hunk at the cursor position inline in the buffer.
736
- M .preview_hunk_inline = function ()
755
+ M .preview_hunk_inline = async . void ( function ()
737
756
local bufnr = current_buf ()
738
757
739
- local hunk = get_cursor_hunk (bufnr )
758
+ local hunk , staged = get_hunk_with_staged (bufnr , true )
740
759
741
760
if not hunk then
742
761
return
743
762
end
744
763
745
764
clear_preview_inline (bufnr )
746
765
747
- local winid --- @type integer
766
+ local winid --- @type integer
748
767
manager .show_added (bufnr , ns_inline , hunk )
749
768
if config ._inline2 then
750
769
if hunk .removed .count > 0 then
751
- winid = manager .show_deleted_in_float (bufnr , ns_inline , hunk )
770
+ winid = manager .show_deleted_in_float (bufnr , ns_inline , hunk , staged )
752
771
end
753
772
else
754
773
manager .show_deleted (bufnr , ns_inline , hunk )
@@ -771,7 +790,7 @@ M.preview_hunk_inline = function()
771
790
if hunk .added .start <= 1 then
772
791
feedkeys (hunk .removed .count .. ' <C-y>' )
773
792
end
774
- end
793
+ end )
775
794
776
795
--- Select the hunk under the cursor.
777
796
M .select_hunk = function ()
@@ -929,8 +948,8 @@ C.blame_line = function(args, _)
929
948
M .blame_line (args )
930
949
end
931
950
932
- --- @param bcache Gitsigns.CacheEntry
933
- --- @param base string ?
951
+ --- @param bcache Gitsigns.CacheEntry
952
+ --- @param base string ?
934
953
local function update_buf_base (bcache , base )
935
954
bcache .base = base
936
955
bcache :invalidate (true )
@@ -1121,14 +1140,14 @@ local function hunks_to_qflist(buf_or_filename, hunks, qflist)
1121
1140
end
1122
1141
end
1123
1142
1124
- --- @param target ' all' | ' attached' | integer | nil
1125
- --- @return table[] ?
1143
+ --- @param target ' all' | ' attached' | integer | nil
1144
+ --- @return table[] ?
1126
1145
local function buildqflist (target )
1127
1146
target = target or current_buf ()
1128
1147
if target == 0 then
1129
1148
target = current_buf ()
1130
1149
end
1131
- local qflist = {} --- @type table[]
1150
+ local qflist = {} --- @type table[]
1132
1151
1133
1152
if type (target ) == ' number' then
1134
1153
local bufnr = target
0 commit comments