lewis6991 / gitsigns.nvim

Git integration for buffers
MIT License
4.91k stars 187 forks source link

fix(blame): avoid right-aligned blame overlapping buftext #1018

Closed joshpencheon closed 3 months ago

joshpencheon commented 3 months ago

Problem

When using virt_text_pos = 'right_align', the placement strategy sometimes doesn't switch to 'eol' (to avoid overlaps) until it's too late.

Hypothesis

When the blame text's length exceeds the available space to the right of the buffer's text, the intention is to switch to the 'eol' extmark placement. However, there were a number of issues that could trip up the time at which it swtiches to 'eol':

Before / After

Before (using reproduction steps below) https://github.com/lewis6991/gitsigns.nvim/assets/30904/631722f6-8e81-4a62-b627-ea2ab42bc9db
After (with fix applied) https://github.com/lewis6991/gitsigns.nvim/assets/30904/b9307503-e14b-4a9d-a862-77b76babfdff

Reproduction steps

With the following minimal.lua:

for name, url in pairs{
  gitsigns = 'https://github.com/lewis6991/gitsigns.nvim',
} do
  local install_path = vim.fn.fnamemodify('gitsigns_issue/'..name, ':p')
  if vim.fn.isdirectory(install_path) == 0 then
    vim.fn.system { 'git', 'clone', '--depth=1', url, install_path }
  end
  vim.opt.runtimepath:append(install_path)
end

require('gitsigns').setup{
  debug_mode = true, -- You must add this to enable debug messages

  -- blame format includes multibyte '«' character:
  current_line_blame_formatter = ' « <committer_time:%R>: <summary> [<abbrev_sha>]',
  current_line_blame_opts = { virt_text_pos = 'right_align' },
  current_line_blame = true,
}

-- Consume some extra window width:
vim.wo.number = true
vim.wo.signcolumn = 'yes'

Run:

nvim --clean -u minimal.lua -- lua/gitsigns/manager.lua