vim-patch:9.1.1885: Wrong restored cursor pos when re-entering buffer after changes

Problem:  Wrong restored cursor position when re-entering a buffer
          previously viewed in a window after making changes to the same
          buffer in another window.
Solution: Adjust per-window "last cursor" positions on buffer changes.
          (zeertzjq)

closes: vim/vim#18655

b2e6b328da
This commit is contained in:
zeertzjq
2025-10-29 06:50:14 +08:00
parent e4db5edb8a
commit a2d4a0fda9
2 changed files with 55 additions and 14 deletions

View File

@@ -619,17 +619,48 @@ func Test_switch_to_previously_viewed_buffer()
vsplit
call cursor(100, 3)
call assert_equal('100', getline('.'))
edit Xotherbuf
buffer Xviewbuf
call assert_equal([0, 100, 3, 0], getpos('.'))
call assert_equal('100', getline('.'))
edit Xotherbuf
wincmd p
normal! gg10dd
wincmd p
buffer Xviewbuf
call assert_equal([0, 90, 3, 0], getpos('.'))
call assert_equal('100', getline('.'))
edit Xotherbuf
wincmd p
normal! ggP
wincmd p
buffer Xviewbuf
call assert_equal([0, 100, 3, 0], getpos('.'))
call assert_equal('100', getline('.'))
edit Xotherbuf
wincmd p
normal! 96gg10ddgg
wincmd p
buffer Xviewbuf
" The original cursor line was deleted, so cursor is restored to the start
" of the line before the deleted range.
call assert_equal([0, 95, 1, 0], getpos('.'))
call assert_equal('95', getline('.'))
normal! u
exe win_id2win(oldwin) .. 'close'
setlocal bufhidden=hide
call cursor(200, 3)
call assert_equal('200', getline('.'))
edit Xotherbuf
buffer Xviewbuf
call assert_equal([0, 200, 3, 0], getpos('.'))
call assert_equal('200', getline('.'))
bwipe! Xotherbuf
bwipe! Xviewbuf