jesseduffield / lazygit

simple terminal UI for git commands
MIT License
53.48k stars 1.86k forks source link

UI shifts to the left and gets cut off when making an amend (when using floating window) #3832

Open alivault opened 3 months ago

alivault commented 3 months ago

Bug When I amend a commit, the lazygit UI shifts to the left and gets cut off (when using a floating window in neovim).

Steps to reproduce the behavior:

  1. open lazygit in a floating window in neovim
  2. amend a commit
  3. observe the UI shifts to the left and gets cut off

Expected behavior The UI should not shift to the left when amending a commit

Screenshot:

Screenshot 2024-08-15 at 3 50 45 PM

Version info:

jxddk commented 1 month ago

I have the same issue when using Lazygit in a Neovim floating window, although it's not limited to amending commits; the issue appears intermittently when hiding and showing the floating window. Hiding and showing the window again fixes the issue (until the next hide/show cycle).

I have an identical issue with Lazydocker, so the issue is not strictly related to this repository.


Version and system information:

$ lazygit --version
commit=, build date=, build source=homebrew, version=0.44.1, os=darwin, arch=arm64, git version=2.47.0
$ nvim --version
NVIM v0.10.2
Build type: Release
LuaJIT 2.1.1727870382
Run "nvim -V1 -v" for more info
$ tmux display -p '#{pane_width}x#{pane_height}'
258x70
● vim-floaterm
    url    https://github.com/voldikss/vim-floaterm
    branch master
    commit 4e28c8d
jxddk commented 1 month ago

After a little investigation, it seems like the root of the issue is that the buffer in Neovim's floating window scrolls to the right and gets stuck there. You can manually fix the scrolling problem while in Neovim with <C-\><C-n>ze. While that may be initially caused by Lazygit's UI framework adding unnecessary blank columns to its right side, I came up with a hacky workaround in my Neovim configuration:

vim.api.nvim_create_autocmd({ "BufEnter" },
  {
    pattern = { "term://lazygit" },
    callback = function()
      vim.schedule(function()
        -- Send keys `ze` to scroll left...
        vim.api.nvim_feedkeys(
          vim.api.nvim_replace_termcodes('<C-\\><C-n>zei', true, true, true),
          'i',
          true)
        -- ...and try (_try_) to disable horizontal scrolling in the buffer
        vim.cmd("set sidescrolloff=" .. vim.o.columns)
        vim.cmd("redraw!")
        end
      end)
    end
  })