scniro / react-codemirror2

Codemirror integrated components for React
MIT License
1.66k stars 193 forks source link

The data object is not created properly on a Undo (Cmd+Z) event in the onBeforeChange hook #210

Open fredfort opened 4 years ago

fredfort commented 4 years ago

Hello there,

When pressing Cmd+Z or Ctrl+Z after deleting few characters in a row, I would expect the data object to contain all the changes that will be reapplied to the editor. Unfortunately, it looks like only one of character appears to be in the object.

From the gif below, the text "some text" get deleted one character after the other. After pressing Cmd+Z, all the text "some text" is displayed again but the text field in the data object only contains the first letter "s".

I would have expected the data object to look like the following

{ cancel: ƒ (), canceled: true, from: Pos {line: 0, ch: 1, sticky: null}, origin: "undo", text: ["some text"], to: Pos {line: 0, ch: 1, sticky: null} }

But instead, we get the following object { cancel: ƒ (), canceled: true, from: Pos {line: 0, ch: 1, sticky: null}, origin: "undo", text: ["s"], to: Pos {line: 0, ch: 1, sticky: null} }

CodeMirrorUndoBug

Can you confirm that this a bug in the library?

Thank you for the great library,

Fred

fredfort commented 4 years ago

One of the workaround is to set the historyEventDelay option to 1 (default is 500ms), this way every action on the text editor will be added to the history (otherwise the history is changed every 500ms)