Slate: Applying changes without editor focus clobbers undo history

Created on 2 May 2019  Â·  8Comments  Â·  Source: ianstormtaylor/slate

Do you want to request a _feature_ or report a _bug_?

Bug

What's the current behavior?

Replicated on https://www.slatejs.org/#/rich-text with latest Chrome browser.

When applying changes to a selection when the editor doesn't have focus, the undo history is clobbered.

To replicate:

  1. Select some text.
  2. Click outside the editor
  3. Click on "Bold" toolbar mark
  4. Click on editor and try to undo. It won't work.

2019-05-01 16 37 00

Further, if you make changes and then try to undo beyond this invalid undo point, the user may no longer redo. This may be a separate issue.

What's the expected behavior?

Undo history should be retained.

bug ♥ help

Most helpful comment

@Slapbox which PR?

All 8 comments

In my local environment I was unsure of how to debug this. Through trial and error I figured out this was the root issue.

Any tips on inspecting why operations fail to undo/redo? I tried logging slate:operation*, but there is a lot of noise, ~and console-logged Immutable objects are tough to inspect =(~ (Edit: Just read about Immutable format extension.)

@quicksnap this PR fixes _some_ of the issues with history, but probably introduces more issues. It's also outdated now, slightly. You'd need to integrate the new changes to the on-history.js file (very minimal.)

If you want to work on improving this, I'd be happy to help. The trouble is that I got it nearly working just in time to step away for a few days, and when I came back, nothing made sense to me anymore. So it moves us closer, but good luck figuring out how =/

PS (I believe it fixes the specific issue you're seeing, but I can't recall with certainty)

@Slapbox which PR?

Ah crap, sorry about that. Here you go: https://github.com/ianstormtaylor/slate/pull/2347

The Master Branch version of that file includes two uses of withoutNormalizing that that PR doesn't include. I believe those are the only changes between that PR and the Master Branch.

By the way, there's a related issue here which might be of interest to you, though it has no solutions itself: https://github.com/ianstormtaylor/slate/issues/2098

Once the problem becomes more of a priority for me, I would be interested in helping. For now, I believe one workaround would be to prevent toolbars from modifying the document without a focused selection. So, one could destroy the selection editor.onBlur and also cause a editor.focus event before any toolbar actions occur.

This is a problem, though, and I would like to know how better to debug what's going wrong. There's a lot of events happening at any given moment, so it's difficult to diagnose what's going wrong with the history.

If I recall, when the editor is blurred, that creates a change in the history stack. I remember that clears all redos. I don't remember it clearing undos.

The way to troubleshoot this is to swap in some of the code from the undo/redo example and paste it into the rich text example so you can observe the history stack in relation to applied marks and your actions.

@ianstormtaylor would you be willing to accept a PR to add rich text to the undo example to make this easier for more people to observe/troubleshoot? I know it makes the example less pure in focus, but I think it could help get more eyeballs on perfecting the undo/redo stack logic.

I believe that this may be fixed by https://github.com/ianstormtaylor/slate/pull/3093, which has changed a lot of the logic in Slate and slate-react especially. I'm going to close this out, but as always, feel free to open a new issue if it persists for you. Thanks for understanding.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vdms picture vdms  Â·  3Comments

chriserickson picture chriserickson  Â·  3Comments

ezakto picture ezakto  Â·  3Comments

ianstormtaylor picture ianstormtaylor  Â·  3Comments

adrianclay picture adrianclay  Â·  3Comments