agitator.nvim icon indicating copy to clipboard operation
agitator.nvim copied to clipboard

Wrapping string breaks blame

Open timsofteng opened this issue 2 years ago • 10 comments
trafficstars

Hello. When text is wrapped to the new line the blame of agitator is incorrect.

Expected behavior: Empty lines oposite wrapped lines or so.

https://github.com/emmanueltouzery/agitator.nvim/assets/51912173/d2c94f06-927c-4970-bfb2-03beb6966ee7

timsofteng avatar May 13 '23 15:05 timsofteng

yes, i'm aware of that. I don't think it's fixable with the current approach of a split window to show the blame contents. Maybe it could be doable with some virtual text or something, but I don't see how.

I'd guess other plugins offering a similar feature (for instance fugitive) have the same flaw probably.. if they don't I could try to check exactly how they did it.

emmanueltouzery avatar May 13 '23 15:05 emmanueltouzery

@emmanueltouzery Yeah. Fugitive works ok.

timsofteng avatar May 13 '23 16:05 timsofteng

hmm I just installed fugitive to check how it does it, but it seems to me to be the same as agitator, with the same flaws. I think it resets the word-wrapping in your buffer when you enable blame... but if you set it back then i can see the problem there too. Make sure to enable word-wrapping in buffer and scroll to the end and you'll see that the end doesn't line up with fugitive as well.

Maybe agitator could disable word-wrap in your buffer when it's activated? That's probably the difference you see with fugitive, i think.

emmanueltouzery avatar May 13 '23 16:05 emmanueltouzery

@emmanueltouzery oh I'm sorry. You are right. Fugitive doesn't work too. I cannot remember why I thought it does. Auto disable and enabling wrapping sounds good to me. I'm just afraid about auto enabling because someone may close agitator's window manually with :q or :bd and I have no ideas how to track it to reenable wrap behavior. But in general this solution sounds totally good.

timsofteng avatar May 13 '23 16:05 timsofteng

yeah i'm not sure about re-enabling back wrapping. I'm thinking just disabling it when the blame is opened and then not touching it anymore.

emmanueltouzery avatar May 13 '23 19:05 emmanueltouzery

@emmanueltouzery I find some implementation with z-index or so.

https://github.com/tanvirtin/vgit.nvim

Maybe it can help.

Alternatively we could open blame in the new tab.

timsofteng avatar May 13 '23 19:05 timsofteng

Hello. Any updates about this issue?

timsofteng avatar May 31 '23 10:05 timsofteng

I actually wrote a naive function to compute real line to screen line when there is word-wrapping. but this will break if the user later resizes the window... so i think this is just not worth doing. it'll always be possible to break it. I'll just disable wordwrap when blame is triggered. Just for future reference, the function was:

local function get_buf_line_to_win_line()
    local bufnr = vim.api.nvim_win_get_buf(0)
    local orig_view = vim.fn.winsaveview()

    local res = {}

    local line_count = vim.api.nvim_buf_line_count(bufnr)
    local cur_line = 1
    while cur_line <= line_count do
        vim.api.nvim_win_set_cursor(0, {cur_line, 0})
        res[cur_line] = vim.fn.winline()
        cur_line = cur_line + 1
    end

    vim.fn.winrestview(orig_view)
    return res
end

emmanueltouzery avatar Jul 15 '23 21:07 emmanueltouzery

@emmanueltouzery Unfortunately break doesn't restore to wrap when I close blame. Totally unusable for me.

timsofteng avatar Aug 09 '23 08:08 timsofteng

i mentioned about that earlier, in https://github.com/emmanueltouzery/agitator.nvim/issues/9#issuecomment-1546732035

probably the best is that you make your own keyboard shortcut on top of these functions here that remembers if line wrapping was set, disables it, calls this blame here, and sets back line wrapping if it was set before. you can totally do this outside of agitator.

maybe you can check what does fugitive do in this case?

emmanueltouzery avatar Aug 09 '23 08:08 emmanueltouzery