codemirror-vim icon indicating copy to clipboard operation
codemirror-vim copied to clipboard

Replaying a macro while it is being recorded hangs the page

Open veluca93 opened this issue 1 year ago • 3 comments

Minimal repro:

import {EditorView, basicSetup} from "codemirror"
import {vim} from "@replit/codemirror-vim"
let editor : EditorView = new EditorView({
  extensions: [vim(), basicSetup, solarizedDark],
  parent: document.body
})

In the resulting editor, typing qaihello<ESC>@a instantly hangs the page, without any obvious way to recover that I could find.

The behaviour in (neo)vim is somewhat better - qaihello<ESC>@a creates an infinite loop of writing hello - but I feel like even that behaviour would be problematic in a web environment, as the user doesn't have a way to interact with the page once this happens.

veluca93 avatar May 21 '24 00:05 veluca93

Currently we rely on maximum call stack size exceptions, so @a repeats the macro 512 times.

Unfortunately performance of the extension on v6 is worse than v5, so repeating macro 500 times takes about a minute. Aside from fixing performance issue, should we also always prevent macro recursion, or can that be useful in some situations and keeping behavior from https://codemirror.net/5/demo/vim.html is ok?

nightwing avatar May 21 '24 07:05 nightwing

I admit I didn't expect that repeating the macro 500 times would lock up the page this badly :-)

I can't at the moment think of a usecase where macro recursion would be useful, but IMO it's best to stick to the vim behaviour if possible (i e. Allow recursion)

veluca93 avatar May 21 '24 08:05 veluca93

For the case of tail-recursion, so playing the macro at the end of recording, we could avoid using a call stack entirely. This would also extend to mutually-recursive recordings like qa@bqqb@aq.

If the recursive call takes place in the middle of a recording then it's down to classic optimizations.

Opisek avatar Jun 07 '24 11:06 Opisek