guardian / scribe

DEPRECATED: A rich text editor framework for the web platform
http://guardian.github.io/scribe/
Apache License 2.0
3.51k stars 245 forks source link

UndoManager and a max length plugin #516

Open muratpurc opened 6 years ago

muratpurc commented 6 years ago

Hi,

I've implemented a simple max length plugin for scribe, the idea is to undo the last action/entry of the user, if the content of the editor has exceeded a defined max length. The state of the plugin is rudimentary yet, but it shows my current problem.

The idea is to do a max length check within the 'content-changed' event, and it works fine so far. But, when I write fast and the length of the editor content crosses the max length, the execution of scribe.undoManager.undo(); results in wrong position of the caret. It jumps to somewhere else, but should stay where it was before, which is usually the last position when typing.

You can see an example here: https://codepen.io/anon/pen/eyJMKB

Just start to type something, the backround of the editor will switch to a light blue color and the caret will jump to the beginning from time to time.

This happens in latest Chrome and in latest Firefox. Any ideas how to solve this issue?