accordproject / cicero-ui

A library of React components for Accord Project templates
Apache License 2.0
29 stars 46 forks source link

Undoing Breaks The Editor #378

Closed jerrybuks closed 4 years ago

jerrybuks commented 4 years ago

Describe the bug undoing multiple times breaks the editor.

To Reproduce Steps to reproduce the behavior:

  1. Go to the demo
  2. Click on anywhere inside "Party A''
  3. move your cursor to right using the right arrow key, to just immediately after the last " of "Party A"
  4. press backspace till you reach the first "
  5. Hold ctrl+z or keep clicking undo, the editor breaks immediately it undoes up till the initial state Expected behavior Undoing should not break the application, but stop once it reaches the expected state

Desktop

irmerk commented 4 years ago

Calling this line in withLinks is erroring because there is no parent:

isSelectionLink = editor => Node.parent(editor, editor.selection.focus.path).type === 'link';

This is stemming from onChange:

if (selection && isSelectionLinkBody(editor)) { setShowLinkModal(true); }
irmerk commented 4 years ago

There seems to be a need to check in onChange to see if the editor is in focus? Trying to put try/catch in isSelectionLink kicks the issue down the road to the next function that's called and has the same issue.