Skip to content

Commit

Permalink
fix(blame): avoid right-aligned blame overlapping buftext
Browse files Browse the repository at this point in the history
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':

- if the buffer line or virtual text contain multibyte characters,
  they weren't counted properly in terms of screen cells that they'd
  consume
- incorrect window identifer was passed when calculating the
  available space, meaning that signs/folds/numbers columns
  weren't properly accounted for
  • Loading branch information
joshpencheon authored and lewis6991 committed May 23, 2024
1 parent a28bb1d commit 20f305d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lua/gitsigns/current_line_blame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ end

--- @param winid integer
--- @return integer
local function win_width(winid)
winid = winid or api.nvim_get_current_win()
local function win_width()
local winid = api.nvim_get_current_win()
local wininfo = vim.fn.getwininfo(winid)[1]
local textoff = wininfo and wininfo.textoff or 0
return api.nvim_win_get_width(winid) - textoff
Expand All @@ -54,7 +54,8 @@ end
--- @param lnum integer
--- @return integer
local function line_len(bufnr, lnum)
return #api.nvim_buf_get_lines(bufnr, lnum - 1, lnum, true)[1]
local line = api.nvim_buf_get_lines(bufnr, lnum - 1, lnum, true)[1]
return api.nvim_strwidth(line)
end

--- @param fmt string
Expand Down Expand Up @@ -103,7 +104,7 @@ local function handle_blame_info(bufnr, lnum, blame_info, opts)
if opts.virt_text then
local virt_text_pos = opts.virt_text_pos
if virt_text_pos == 'right_align' then
if #virt_text_str > (win_width(0) - line_len(bufnr, lnum)) then
if api.nvim_strwidth(virt_text_str) > (win_width() - line_len(bufnr, lnum)) then
virt_text_pos = 'eol'
end
end
Expand Down

0 comments on commit 20f305d

Please sign in to comment.