claude-baseline-1752140337 (startup)

This commit is contained in:
zolinthecow 2025-07-10 02:38:57 -07:00
parent 879e5dd577
commit 144ac12df7
1 changed files with 23 additions and 4 deletions

View File

@ -127,6 +127,15 @@ function M.apply_diff_visualization(bufnr)
local new_line_num = hunk.new_start -- 1-indexed line number in new file local new_line_num = hunk.new_start -- 1-indexed line number in new file
local old_line_num = hunk.old_start -- 1-indexed line number in old file local old_line_num = hunk.old_start -- 1-indexed line number in old file
-- First, detect if this hunk is a replacement (has both - and + lines)
local has_deletions = false
local has_additions = false
for _, diff_line in ipairs(hunk.lines) do
if diff_line:match('^%-') then has_deletions = true end
if diff_line:match('^%+') then has_additions = true end
end
local is_replacement = has_deletions and has_additions
for _, diff_line in ipairs(hunk.lines) do for _, diff_line in ipairs(hunk.lines) do
if diff_line:match('^%+') then if diff_line:match('^%+') then
-- This is an added line - it exists in the current buffer at new_line_num -- This is an added line - it exists in the current buffer at new_line_num
@ -135,8 +144,14 @@ function M.apply_diff_visualization(bufnr)
-- Don't advance old_line_num for additions -- Don't advance old_line_num for additions
elseif diff_line:match('^%-') then elseif diff_line:match('^%-') then
-- This is a deleted line - show as virtual text above current position -- This is a deleted line - show as virtual text above current position
-- For replacements, the deletion should appear above the addition
local del_line = new_line_num - 1
if is_replacement and #additions > 0 then
-- Place deletion above the first addition
del_line = additions[1]
end
table.insert(deletions, { table.insert(deletions, {
line = new_line_num - 1, -- 0-indexed, show above current position line = del_line, -- 0-indexed
text = diff_line:sub(2), text = diff_line:sub(2),
}) })
old_line_num = old_line_num + 1 old_line_num = old_line_num + 1
@ -160,13 +175,17 @@ function M.apply_diff_visualization(bufnr)
end end
end end
-- Show pure deletions as virtual text above their position -- Show deletions as virtual text above their position with full-width background
for j, del in ipairs(deletions) do for j, del in ipairs(deletions) do
if del.line >= 0 and del.line <= #buf_lines then if del.line >= 0 and del.line <= #buf_lines then
-- Show deletion with a more subtle approach to avoid visual artifacts -- Calculate full width for the deletion line
local text = '- ' .. del.text
local win_width = vim.api.nvim_win_get_width(0)
local padding = string.rep(' ', math.max(0, win_width - vim.fn.strdisplaywidth(text)))
vim.api.nvim_buf_set_extmark(bufnr, ns_id, del.line, 0, { vim.api.nvim_buf_set_extmark(bufnr, ns_id, del.line, 0, {
virt_lines = {{ virt_lines = {{
{'- ' .. del.text, 'DiffDelete'} {text .. padding, 'DiffDelete'}
}}, }},
virt_lines_above = true, virt_lines_above = true,
id = 3000 + i * 100 + j id = 3000 + i * 100 + j