fix: inline2 fixes

This commit is contained in:
Lewis Russell 2023-09-23 14:27:37 +01:00 committed by Lewis Russell
parent ecc857f73b
commit 664da1fcf3
2 changed files with 18 additions and 6 deletions

View File

@ -725,6 +725,12 @@ local function clear_preview_inline(bufnr)
api.nvim_buf_clear_namespace(bufnr, ns_inline, 0, -1)
end
--- @param keys string
local function feedkeys(keys)
local cy = api.nvim_replace_termcodes(keys, true, false, true)
api.nvim_feedkeys(cy, 'n', false)
end
--- Preview the hunk at the cursor position inline in the buffer.
M.preview_hunk_inline = function()
local bufnr = current_buf()
@ -759,12 +765,10 @@ M.preview_hunk_inline = function()
once = true,
})
-- Virtual lines will be hidden if cursor is on the top row, so automatically
-- scroll the viewport.
if api.nvim_win_get_cursor(0)[1] == 1 then
local keys = hunk.removed.count .. '<C-y>'
local cy = api.nvim_replace_termcodes(keys, true, false, true)
api.nvim_feedkeys(cy, 'n', false)
-- Virtual lines will be hidden if they are placed on the top row, so
-- automatically scroll the viewport.
if hunk.added.start <= 1 then
feedkeys(hunk.removed.count .. '<C-y>')
end
end

View File

@ -322,6 +322,8 @@ function M.show_deleted_in_float(bufnr, nsd, hunk)
vim.cmd('normal ' .. vim.api.nvim_replace_termcodes('z<CR>', true, false, true))
end)
local last_lnum = api.nvim_buf_line_count(bufnr)
-- Apply highlights
for i = hunk.removed.start, hunk.removed.start + hunk.removed.count do
@ -329,6 +331,7 @@ function M.show_deleted_in_float(bufnr, nsd, hunk)
hl_group = 'GitSignsDeleteVirtLn',
hl_eol = true,
end_row = i,
strict = i == last_lnum,
priority = 1000,
})
end
@ -372,8 +375,13 @@ function M.show_added(bufnr, nsw, hunk)
for _, region in ipairs(added_regions) do
local offset, rtype, scol, ecol = region[1] - 1, region[2], region[3] - 1, region[4] - 1
-- Special case to handle cr at eol in buffer but not in show text
local cr_at_eol_change = rtype == 'change' and vim.endswith(hunk.added.lines[offset + 1], '\r')
api.nvim_buf_set_extmark(bufnr, nsw, start_row + offset, scol, {
end_col = ecol,
strict = not cr_at_eol_change,
hl_group = rtype == 'add' and 'GitSignsAddInline'
or rtype == 'change' and 'GitSignsChangeInline'
or 'GitSignsDeleteInline',