Skip to content

Commit

Permalink
Merge pull request neovim#26361 from luukvbaal/invalid
Browse files Browse the repository at this point in the history
fix(extmarks): restore old position before revalidating
  • Loading branch information
bfredl authored Dec 5, 2023
2 parents 1457272 + 1cc358a commit ca4fe08
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/nvim/extmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,16 +389,16 @@ void extmark_apply_undo(ExtmarkUndoObject undo_info, bool undo)
} else if (undo_info.type == kExtmarkSavePos) {
ExtmarkSavePos pos = undo_info.data.savepos;
if (undo) {
if (pos.old_row >= 0) {
extmark_setraw(curbuf, pos.mark, pos.old_row, pos.old_col);
}
if (pos.invalidated) {
MarkTreeIter itr[1] = { 0 };
MTKey mark = marktree_lookup(curbuf->b_marktree, pos.mark, itr);
mt_itr_rawkey(itr).flags &= (uint16_t) ~MT_FLAG_INVALID;
MTPos end = marktree_get_altpos(curbuf->b_marktree, mark, itr);
buf_put_decor(curbuf, mt_decor(mark), mark.pos.row, end.row < 0 ? mark.pos.row : end.row);
}
if (pos.old_row >= 0) {
extmark_setraw(curbuf, pos.mark, pos.old_row, pos.old_col);
}
// Redo
} else {
if (pos.row >= 0) {
Expand Down
19 changes: 10 additions & 9 deletions test/functional/api/extmark_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1628,26 +1628,27 @@ describe('API/extmarks', function()
screen = Screen.new(40, 6)
screen:attach()
feed('dd6iaaa bbb ccc<CR><ESC>gg')
set_extmark(ns, 1, 0, 0, { invalidate = true, sign_text = 'S1' })
set_extmark(ns, 2, 1, 0, { invalidate = true, sign_text = 'S2' })
meths.set_option_value('signcolumn', 'auto:2', {})
set_extmark(ns, 1, 0, 0, { invalidate = true, sign_text = 'S1', end_row = 1 })
set_extmark(ns, 2, 1, 0, { invalidate = true, sign_text = 'S2', end_row = 2 })
-- mark with invalidate is removed
command('d')
command('d2')
screen:expect([[
S2^aaa bbb ccc |
aaa bbb ccc |
aaa bbb ccc |
aaa bbb ccc |
aaa bbb ccc |
|
|
]])
-- mark is restored with undo_restore == true
command('silent undo')
screen:expect([[
S1^aaa bbb ccc |
S2aaa bbb ccc |
aaa bbb ccc |
aaa bbb ccc |
aaa bbb ccc |
S1 ^aaa bbb ccc |
S1S2aaa bbb ccc |
S2 aaa bbb ccc |
aaa bbb ccc |
aaa bbb ccc |
|
]])
-- mark is deleted with undo_restore == false
Expand Down

0 comments on commit ca4fe08

Please sign in to comment.