Repository: neovim
Issue: on_lines: new_lastline does not match original deletion after undo/redo
Labels: bug

### Neovim version (nvim -v)

0.6.0 b74916c

### Vim (not Nvim) behaves the same?

N/A

### Operating system/version

Fedora 34

### Terminal name/version

kitty

### $TERM environment variable

xterm-kitty

### Installation

source build

### How to reproduce the issue

Repro script
```lua
local edit_buf = vim.api.nvim_create_buf(true, true)

vim.api.nvim_set_current_buf(edit_buf)

vim.api.nvim_buf_set_lines(edit_buf, 0, -1, true, { 'ab', 'cd', 'ef', 'gh' })

local prev_lines = vim.api.nvim_buf_get_lines(edit_buf, 0, -1, true)
local curr_lines = prev_lines

local callback = function(buf, _, tick, firstline, lastline, new_lastline, _, _, _)
  curr_lines = vim.api.nvim_buf_get_lines(buf, 0, -1, true)
  print('on_lines callback occured')
  print(vim.inspect({
    prev_lines=prev_lines,
    curr_lines=curr_lines,
    tick=tick,
    firstline=firstline,
    lastline=lastline,
    new_lastline=new_lastline
  }))
  prev_lines=curr_lines
end

vim.api.nvim_set_current_buf(edit_buf)
--local key = vim.api.nvim_replace_termcodes("ggdGu<C-r>", true, false, true)

vim.api.nvim_buf_attach(edit_buf, false, { on_lines = callback })
--vim.api.nvim_feedkeys(key, 'n', true)
```

Type `ggdG`

You will see the following printouts
```
{                                                                                                                              
  curr_lines = { "" },                                                                                                         
  firstline = 0,                                                                                                               
  lastline = 4,                                                                                                                
  new_lastline = 0,                                                                                                            
  prev_lines = { "ab", "cd", "ef", "gh" },                                                                                     
  tick = 3                                                                                                                     
}                                                                                                                              
3 fewer lines                                                                                                                  
on_lines callback occured                                                                                                      
{                                                                                                                              
  curr_lines = { "ab", "cd", "ef", "gh" },                                                                                     
  firstline = 0,                                                                                                               
  lastline = 1,                                                                                                                
  new_lastline = 4,                                                                                                            
  prev_lines = { "" },                                                                                                         
  tick = 4                                                                                                                     
}                                                                                                                              
4 more lines; before #2  2 seconds ago                                                                                         
on_lines callback occured                                                                                                      
{                                                                                                                              
  curr_lines = { "" },                                                                                                         
  firstline = 0,                                                                                                               
  lastline = 4,                                                                                                                
  new_lastline = 1,                                                                                                            
  prev_lines = { "ab", "cd", "ef", "gh" },                                                                                     
  tick = 6                                                                                                                     
}
```

Note that in the final redo operations, the new_lastline is 1, whereas in the original deletion operation, new_lastline was 0. This affects the incremental sync implementation used by LSP.

### Expected behavior

See above

### Actual behavior

See above