lewis6991 / gitsigns.nvim

Git integration for buffers
MIT License
5.14k stars 192 forks source link

Wrong cursor position after inputting i in normal mode #1106

Closed turingzhi closed 3 months ago

turingzhi commented 3 months ago

Description

After detecting all plugins in my nvim, I found gitsigns has some problems about cursor position. When I input i in normal mode, the cursor should be in the position but the cursor is actually in the position where is one position before where it should be. This case happens when the cursor is on " in (". When I disabled gitsigns plugin, the problem disappears. And this case is not happening every time. The probability of happening is around 50%.

Neovim version

v0.10.1

Operating system and version

MacOS M1 Sonoma14.2.1 (23C71)

Expected behavior

The cursor should be in where it should be like in normal nvim

Actual behavior

When I input i in normal mode and the cursor is on " in (", the cursor sometimes is in right place, sometimes is before (.

Minimal config

return {
    {
        "lewis6991/gitsigns.nvim",
        config = function()
            require('gitsigns').setup {
                signs                        = {
                    add          = { text = '┃' },
                    change       = { text = '┃' },
                    delete       = { text = '_' },
                    topdelete    = { text = '‾' },
                    changedelete = { text = '~' },
                    untracked    = { text = '┆' },
                },
                signs_staged                 = {
                    add          = { text = '┃' },
                    change       = { text = '┃' },
                    delete       = { text = '_' },
                    topdelete    = { text = '‾' },
                    changedelete = { text = '~' },
                    untracked    = { text = '┆' },
                },
                signs_staged_enable          = true,
                signcolumn                   = true, -- Toggle with `:Gitsigns toggle_signs`
                numhl                        = false, -- Toggle with `:Gitsigns toggle_numhl`
                linehl                       = false, -- Toggle with `:Gitsigns toggle_linehl`
                word_diff                    = false, -- Toggle with `:Gitsigns toggle_word_diff`
                watch_gitdir                 = {
                    follow_files = true
                },
                auto_attach                  = true,
                attach_to_untracked          = false,
                current_line_blame           = false, -- Toggle with `:Gitsigns toggle_current_line_blame`
                current_line_blame_opts      = {
                    virt_text = true,
                    virt_text_pos = 'eol', -- 'eol' | 'overlay' | 'right_align'
                    delay = 1000,
                    ignore_whitespace = false,
                    virt_text_priority = 100,
                },
                current_line_blame_formatter = '<author>, <author_time:%R> - <summary>',
                sign_priority                = 6,
                update_debounce              = 100,
                status_formatter             = nil, -- Use default
                max_file_length              = 40000, -- Disable if file is longer than this (in lines)
                preview_config               = {
                    -- Options passed to nvim_open_win
                    border = 'single',
                    style = 'minimal',
                    relative = 'cursor',
                    row = 0,
                    col = 1
                },
            }
            --          require('gitsigns').setup({
            --              signs = {
            --                  add          = { text = '▎' },
            --                  change       = { text = '░' },
            --                  delete       = { text = '_' },
            --                  topdelete    = { text = '▔' },
            --                  changedelete = { text = '▒' },
            --                  untracked    = { text = '┆' },
            --              },
            --          })
            vim.keymap.set("n", "<leader>g-", ":Gitsigns prev_hunk<CR>", { noremap = true, silent = true })
            vim.keymap.set("n", "<leader>g=", ":Gitsigns next_hunk<CR>", { noremap = true, silent = true })
            vim.keymap.set("n", "<leader>gb", ":Gitsigns blame_line<CR>", { noremap = true, silent = true })
            vim.keymap.set("n", "<leader>gr", ":Gitsigns reset_hunk<CR>", { noremap = true, silent = true })
            vim.keymap.set("n", "hu", ":Gitsigns preview_hunk<CR>", { noremap = true, silent = true })
        end
    },
    {
        "kdheepak/lazygit.nvim",
        keys = { "<c-g>" },
        config = function()
            vim.g.lazygit_floating_window_scaling_factor = 1.0
            vim.g.lazygit_floating_window_winblend = 0
            vim.g.lazygit_use_neovim_remote = true
            vim.keymap.set("n", "<c-g>", ":LazyGit<CR>", { noremap = true, silent = true })
        end
    },
    -- {
    --  "APZelos/blamer.nvim",
    --  config = function()
    --      vim.g.blamer_enabled = true
    --      vim.g.blamer_relative_time = true
    --  end
    -- }
}

Steps to reproduce

  1. open any file with nvim
  2. move cursor to " in (" or ' in ('
  3. input i to go to insert mode
  4. then the cursor might be in before ( Snipaste_2024-08-05_12-57-29

Gitsigns debug messages

No response

Gitsigns cache

No response

lewis6991 commented 3 months ago

Config isn't minimal.