Skip to content

Undo may open the wrong fold #80

@lacygoill

Description

@lacygoill

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions