replit / codemirror-vim

Vim keybindings for CM6
https://www.npmjs.com/package/@replit/codemirror-vim
MIT License
289 stars 30 forks source link

[BUG]: error A document must have at least one line #156

Closed oeyoews closed 8 months ago

oeyoews commented 8 months ago

I made codemirror6 into a tiddlywiki plugin, and added the codemirror-vim extension. Everything works very well, whether it is hosted locally or online https://oeyoews.github.io/tiddlywiki-codemirror6/#%24%3A%2Fplugins%2Foeyoews%2Ftiddlywiki-codemirror-6

But on tiddlyhost's hosting website (https://cm6-bug-on-tiddlyhost.tiddlyhost.com), I encountered the following error. I am not sure whether it is a problem with tiddlyhost or codemirror-vim.

https://github.com/replit/codemirror-vim/assets/72405338/1fc016d7-d217-4e84-b638-4d8e866a91b6

Steps to reproduce: Enter xxx, select and delete them all and the problem in the video will be triggered.

nightwing commented 8 months ago

This does not seem to be related to codemirror-vim, because deleting text in insert mode is handled by codemirror itself, not by vim plugin.

oeyoews commented 8 months ago

But if cm6 does not enable vim mode, there will be no such problem.

oeyoews commented 8 months ago

https://github.com/replit/codemirror-vim/assets/72405338/494d0314-65f4-443e-b2d6-e0cfc9284128

nightwing commented 8 months ago

is there a way to load https://cm6-bug-on-tiddlyhost.tiddlyhost.com/ with non-minimized code?

oeyoews commented 8 months ago

https://github.com/tiddly-gittly/Modern.TiddlyDev/issues/60, I tried it, and there seems to be something wrong with this packaged framework.

nightwing commented 8 months ago

One part of the issue is that LineBreakPlaceholder = "\uffff"; is turned to kn = ""; in minification, leading to "".split("") returning [], while "".split("\uffff") would return [""].

Another part, which may explain why the issue does not happen without vim, is that applyDOMChange in codemirror is being triggered when deleting text even though in other places it is being handled directly from delete keypress, but i did not figure out yet why is that happening.

oeyoews commented 8 months ago

For additional information, if press enter to nextline on vim insert tmode, codemirror6 editor not update(These problems will not be triggered when running locally or on the github web pages, which is very strange)

nightwing commented 8 months ago

Looks like when adding vim keymap you are removing the https://codemirror.net/docs/ref/#commands.standardKeymap so commands added by it like Backspace, Delete or Enter are missing.

oeyoews commented 8 months ago

Indeed, when opening vimmode, I did not add defaultkeymap, which caused an error. Now I have fixed it, but what I am most curious about is why this bug is not triggered locally or on other websites. It only occurs on tiddlyhost

pmario commented 8 months ago

@oeyoews can this issue be closed here?

nightwing commented 8 months ago

Most likely locally you don't have LineBreakPlaceholder bug, so pressing enter there would work as it does on contenteditable node, but would not indent code.