Slate: state.decorations don't update when operations are applied

Created on 26 Oct 2017  Â·  5Comments  Â·  Source: ianstormtaylor/slate

Do you want to request a feature or report a bug?

bug

What's the current behavior?

In the highlight example, type a word in the search box, then delete that word (or change it slightly) in the paragraph. The highlight will still be visible applied to the wrong characters.

search_slate

What's the expected behavior?

The highlight should be removed if the text changes. I think only a minor tweak to the onInputChange method is needed. When I have some extra time this week I can look into it.

bug ♥ help

Most helpful comment

I just realized...

This is due to state.decorations not being updated in the same way that state.selection is updated in ./operations/apply.js. Every time an operation is applied, the logic checks to see if the selection range needs to be shifted/removed based on what was inserted/removed. If the same thing happened for decorations this would be fixed.

I think we should fix it at the source, instead of in the example.

All 5 comments

Ah good call. Actually if we just extracted the body of onInputChange out into an updateDecorators method, and called it from both onInputChange and onChange, I think that would fix it.

I just realized...

This is due to state.decorations not being updated in the same way that state.selection is updated in ./operations/apply.js. Every time an operation is applied, the logic checks to see if the selection range needs to be shifted/removed based on what was inserted/removed. If the same thing happened for decorations this would be fixed.

I think we should fix it at the source, instead of in the example.

@ianstormtaylor any update on this bug?

Not from me personally, because I’m not affected by it right now. But if anyone else wanted to PR a fix that would be awesome!

This is fixed in the latest versions of Slate.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JSH3R0 picture JSH3R0  Â·  3Comments

ianstormtaylor picture ianstormtaylor  Â·  3Comments

bengotow picture bengotow  Â·  3Comments

chrpeter picture chrpeter  Â·  3Comments

vdms picture vdms  Â·  3Comments