FabijanZulj / blame.nvim

Neovim fugitive style git blame plugin
MIT License
300 stars 19 forks source link

blame lines alignment is incorrect #6

Open skoch13 opened 1 year ago

skoch13 commented 1 year ago

In my setup, blame.nvim window is not aligned with the main buffer. Please see the screenshots attached.

Screenshot 2023-08-15 at 09 43 06 Screenshot 2023-08-15 at 09 44 49

FabijanZulj commented 1 year ago

Can you give some more info please, do you have anything special manipulating the window/buffer or something like that.

What is your 'scrolloff' option set to?

I will try to recreate it in any case. I had quite some issues with it during development and testing but thought I solved it.

Thanks!

skoch13 commented 1 year ago

I use LazyVim, so options are provided by the distribution.

Answering your questions:

 opt.scrolloff = 4
 opt.sidescrolloff = 8

I also use edgy.nvim, but turning it off did not resolve the bug.

FabijanZulj commented 1 year ago

Really weird, I also use LazyVim and edgy.nvim . I will check it further as soon as I come back from vacation :)

danielt812 commented 1 year ago

My blame buffer was misaligned as well. Mine was due to having the winbar set on the main buffer (in my case nvim-navic displayed inside of lualine winbar). I wrote this autocmd to hide the lualine winbar when blame is open. You can tweak this snippet to temporarily disable the winbar if that is causing your misalignment issue as well.

local winbar_settings_group = vim.api.nvim_create_augroup("winbar_settings", { clear = true })

vim.api.nvim_create_autocmd({ "WinEnter", "WinResized" }, {
  group = winbar_settings_group,
  desc = "Hide lualine winbar when blame is open",
  callback = function()
    local win_ids = vim.api.nvim_list_wins()

    for _, win_id in ipairs(win_ids) do
      local buf_id = vim.api.nvim_win_get_buf(win_id)
      local buf_ft = vim.api.nvim_buf_get_option(buf_id, "filetype")
      if buf_ft == "blame" then
        require("lualine").hide({
          place = { "winbar" },
          unhide = false,
        })
        break -- Exit the loop since a 'blame' filetype was found
      else
        require("lualine").hide({
          place = { "winbar" },
          unhide = true,
        })
      end
    end
  end,
})
okuramasafumi commented 9 months ago

This might be a different issue, but in my environment, when the line is so long and wrapped, the alignment gets incorrect.

blame buffer
1: 1: some very long text
2: first line continues
3: 2: new line
FabijanZulj commented 4 months ago

The wrapping issue should be fixed now, but I did not find a good solution for the winbar issue so I will leave this open

Amleto commented 4 months ago

@FabijanZulj I was using blame.window_blame is_window_open() to toggle my barbecue (navic) off when blame is open, but this has just been removed.

I tried using require("blame.views.window_view"):is_open() but this returns false even even the window is open.

What do you suggest?

FabijanZulj commented 4 months ago

@Amleto I have added a new method require("blame").is_open() that you can use to check if a view is open like you were until now.

If you are using barbecue it should work out of the box, and the windows should be aligned as now we also copy the winbar state to the blame window on opening. However, if you are using something like lualine winbar that opens and closes depending on your cursor position you will have to do something. I have also added 'User' events that you can create autocommand handlers for.

They are:

Both of these events send the blame view type in the data field. So you can do something like this:

      vim.api.nvim_create_autocmd("User", {
        pattern = "BlameViewOpened",
        callback = function(event)
          local blame_type = event.data
          if blame_type == "window" then
            require("barbecue.ui").toggle(false)
          end
        end,
      })

      vim.api.nvim_create_autocmd("User", {
        pattern = "BlameViewClosed",
        callback = function(event)
          local blame_type = event.data
          if blame_type == "window" then
            require("barbecue.ui").toggle(true)
          end
        end,
      })

(using barbecue as an example here, but I believe it should work well without it too)

Amleto commented 4 months ago

Thanks! It does work "out of the box" for the initial blame, but I noticed when going to a new blame in the stack (first time pressing tab) then code file loses its barbecue header