Slate: remove `isFocused` and `marks` from `Selection`?

Created on 21 Oct 2019  Â·  3Comments  Â·  Source: ianstormtaylor/slate

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

Idea / debt.

What's the current behavior?

Right now the isFocused and marks properties of a Selection are stored in the data model. But these things are tracking editor-specific state that doesn't apply across editor instance. This leads to leakiness:

It doesn't make sense to send a "blurring" selection operation to another editor while collaborating. It doesn't make sense for the history to be affected by blurring/focusing operations, or for undo to leave the editor blurred. And it doesn't make sense for selection marks to preserve across undos either—or at least Google Docs doesn't. All of these operations have to get ignored right now in these scenarios.

What's the expected behavior?

I think it would be better to have these properties be local-only. And closured to an instance of the editor (implemented in the React/DOM plugins instead).

This also means that Selection becomes just a plain Range, which is convenient.

debt idea ✶ breaking

Most helpful comment

I agree on both those counts. I have code to massage those cases around undo and focus / blur, and it would be nice to get rid of them. Anecdotally, selection vs range has been tough for reviewers to wrap their minds around. I think this is a great idea.

All 3 comments

I agree on both those counts. I have code to massage those cases around undo and focus / blur, and it would be nice to get rid of them. Anecdotally, selection vs range has been tough for reviewers to wrap their minds around. I think this is a great idea.

So, my instinct is that moving these variables into local wouldn't affect this particular need but it feels like it's worth bringing up just in case it impacts other decisions in this area.

One area where Slate currently can't handle compositions is when there are marks applied to a collapsed selection. Since the marks aren't reflected in the DOM when the user starts a composition, the text does not show the marks as it is being composed (e.g. bolded text will not be bold). Once the composition is completed, the DOM can be updated and the text shows as bold.

The solution is that when the user bolds text on a collapsed selection, a DOM node is inserted for the bold with no text inside and the selection is placed inside that node. Then when the user starts composing, it should be within that node.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yalu picture yalu  Â·  3Comments

ianstormtaylor picture ianstormtaylor  Â·  3Comments

ianstormtaylor picture ianstormtaylor  Â·  3Comments

YurkaninRyan picture YurkaninRyan  Â·  3Comments

chrpeter picture chrpeter  Â·  3Comments