vim-auto-save icon indicating copy to clipboard operation
vim-auto-save copied to clipboard

Duplicate entry is created in undo history

Open Asheq opened this issue 5 years ago • 4 comments

This duplicate entry is added after an InsertLeave and after the user moves the cursor.

To reproduce:

  1. Enter insert-mode.

  2. Type anything.

  3. Exit insert mode.

    • Autosave is triggered and undo history is updated, as expected.
  4. Move the cursor using any motion.

    • Undo list is updated again with no actual diff, which is not expected.

Here is an example below. I am using undotree to visualize the undo history. example

Asheq avatar Jan 03 '20 21:01 Asheq

FYI: This issue (as well #41) goes away when I trigger an auto-save on only CursorHold events.

let g:auto_save_events = ["CursorHold"]
set updatetime=300

So far, things are working well for me using these settings!

Asheq avatar Jan 07 '20 23:01 Asheq

I think OP has a valid point. Plugin creates some modification,( that comes up in undo history) in every event. @Asheq, I tried with your settings.

rjshrjndrn avatar Feb 02 '20 03:02 rjshrjndrn

@Asheq @rjshrjndrn Hello! I have no time to investigate and fix this issue, sorry! But if you know how to fix that a PR is very welcome!

907th avatar Feb 12 '20 09:02 907th

my solution:

let g:undo_skip_max_lines = 1000

function! Undo(it) abort "{{{
  function! Lines() abort "{{{
    return nvim_buf_get_lines(0, 0, g:undo_skip_max_lines, v:false)
  endfunction "}}}
  if nvim_buf_line_count(0) < g:undo_skip_max_lines && a:it < 10
    let pre = Lines()
    normal! u
    let post = Lines()
    if pre == post
      return Undo(a:it + 1)
    endif
  else
    normal! u
  endif
endfunction "}}}

nnoremap u <cmd>call Undo(0)<cr>

skip empty changes in undo.

tek avatar Jun 07 '20 15:06 tek