kylechui / nvim-surround

Add/change/delete surrounding delimiter pairs with ease. Written with :heart: in Lua.
MIT License
2.92k stars 60 forks source link

Deleting or changing pairs complains "Line value outside range" #241

Closed Chattille closed 1 year ago

Chattille commented 1 year ago

Checklist

Neovim Version

NVIM v0.9.0

Plugin Version

Tagged (Stable)

Minimal Configuration

local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'

if not vim.loop.fs_stat(lazypath) then
    vim.fn.system {
        'git',
    'clone',
    '--filter=blob:none',
    'https://github.com/folke/lazy.nvim.git',
    '--branch=stable',
    lazypath,
    }
end

vim.opt.rtp:prepend(lazypath)

require('lazy').setup {
    { 'kylechui/nvim-surround', config = true },
}

Sample Buffer

(test)

Keystroke Sequence

  1. Insert something below (test):
    (test)
    ------
  2. Move to the new line and enter visual mode.
  3. Delete the second line.
  4. Move inside the parens and ds) or cs)}.

https://github.com/kylechui/nvim-surround/assets/53635735/0bc78098-4382-4d6b-aac3-de03eb3425f9

Expected behavior

Parens deleted or changed.

Actual behavior

E5108: Error executing lua ...are/nvim/lazy/nvim-surround/lua/nvim-surround/buffer.lua
:58: Line value outside range
stack traceback:
        [C]: in function 'nvim_buf_set_mark'
        ...are/nvim/lazy/nvim-surround/lua/nvim-surround/buffer.lua:58: in function 's
et_mark'
        ...are/nvim/lazy/nvim-surround/lua/nvim-surround/buffer.lua:116: in function '
set_operator_marks'
        ...re/nvim/lazy/nvim-surround/lua/nvim-surround/motions.lua:22: in function 'g
et_selection'
        ...are/nvim/lazy/nvim-surround/lua/nvim-surround/config.lua:290: in function <
...are/nvim/lazy/nvim-surround/lua/nvim-surround/config.lua:289>
        ...hare/nvim/lazy/nvim-surround/lua/nvim-surround/utils.lua:33: in function 'g
et_nearest_selections'
        ...share/nvim/lazy/nvim-surround/lua/nvim-surround/init.lua:159: in function '
delete_surround'
        ...share/nvim/lazy/nvim-surround/lua/nvim-surround/init.lua:298: in function <
...share/nvim/lazy/nvim-surround/lua/nvim-surround/init.lua:289>

Additional context

This happens when mark < or > is invalid.

kylechui commented 1 year ago

Thanks for the detailed reproduction steps and information! It really helped me diagnose this quickly. Please try the latest commit on main and see if that fixes the issue.

Chattille commented 1 year ago

Thanks! Now it works a treat.