Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undo may open the wrong fold #80

Open
lacygoill opened this issue May 12, 2020 · 1 comment
Open

Undo may open the wrong fold #80

lacygoill opened this issue May 12, 2020 · 1 comment

Comments

@lacygoill
Copy link

Describe the bug

The undo command may open the wrong fold.

To Reproduce

Run this shell command (you'll need to update the path to the plugin):

vim -Nu NONE -S <(cat <<'EOF'
    set rtp^=/path/to/vim-repeat
    nno <c-b> xp:call repeat#set("\<lt>c-b>")<cr>
    let buf =<< trim END
        " fold A {{{1
        " some text
        " fold B {{{1
        " some text
    END
    %d
    pu!=buf
    setl fdm=marker
EOF
) /tmp/file
  • Press zo to open the B fold.
  • Press C-b to exchange the position of two characters and invoke repeat#set() which causes the wrapper mapping around the undo command to be installed.
  • Press zc to close the B fold.
  • Press k to move on the A fold.
  • Press u to undo the last change.

Result: The A fold is opened.

Expected behavior

The B fold is opened.

Screenshots

gif

Environment

  • plugin version: c947ad2
  • Vim version: 8.2 Included patches: 1-740
  • OS: Ubuntu 16.04.6 LTS
  • Terminal: XTerm(322)

Additional context

The issue is due to the zv command being executed too early:

exe (&foldopen =~# 'undo\|all' ? 'norm! zv' : '')

The undo command is written in the typeahead via feedkeys() which doesn't execute it immediately. In contrast, zv is executed via :norm which does execute the command immediately. As a result, zv is executed before the undo command, while it should be executed after.

There are several solutions, but I think the simplest one is to just pass zv to feedkeys().


It's a regression introduced by 1b82cad.

@lacygoill
Copy link
Author

lacygoill commented May 12, 2020

There are several solutions, but I think the simplest one is to just pass zv to feedkeys().

Actually no, the simplest fix would be to use the t flag: #81 (comment)

Edit: t would cause the undo/redo command to be saved twice during a recording which is wrong. So, passing zv to feedkeys() is better.

Edit 2: Yes, but only on the condition that zv is really needed; that is if the cursor is in a closed fold; otherwise, we may prevent u, U, and C-r from printing some info about the undo state, as reported in #27. See this comment for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant