Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Decorators with fixed-length ranges makes editing unstable #414

Open
Soreine opened this issue May 24, 2016 · 4 comments
Open

Decorators with fixed-length ranges makes editing unstable #414

Soreine opened this issue May 24, 2016 · 4 comments

Comments

@Soreine
Copy link

Soreine commented May 24, 2016

Hello,
I have been struggling with decorators recently. When decorators decorate arbitrary spans of characters (that do not match words), editing those same spans results in weird behaviors from the editor.

Here is a Gist of a single HTML page with simple code to reproduce the issue. The Gist shows an editor with the first 10 characters of each block highlighted in red. Positioning the caret (represented by []) at the start of the text:

[]Accusantium libero ...

And typing ABC, results in this weird state:

ABACc[]cusanttiiium libero ...

Do decorators need to adapt to the editing in some ways ? Are there some rules I ignore about what can be decorated and what should not ?

Thank you for your time.

@sophiebits
Copy link
Contributor

This just seems like a bug to me. Thanks for reporting.

@johanneslumpe
Copy link
Contributor

The culprit is our editOnInput handler which is used for spellcheck changes mostly. It compares the length of the model's text with the one from the DOM. Since a decorator wraps its children within a DOM element, the length of that node's content won't match with what we see in the model (due to the decorator having a constant length). And this leads to corrupt state for normal text input as well as spellcheck changes within a constant length decorator because we use the delta between new and old text to figure out how to adjust the selection.

This issue affects all browsers except Firefox because there we rely on Firefox's internal selection state and do force update it.

This issue gets worse if we try to apply a spellcheck correction to a word whose first character is at the lower bound or whose last character is at the upper bound of the decorator. In Chrome that word will then be put into its own DOM node, thus really messing up our comparison.

@Soreine Soreine changed the title Decorators with arbitrary ranges makes editing unstable Decorators with fixed-length ranges makes editing unstable May 26, 2016
@hellendag
Copy link

I think editOnInput is doing its job as expected here, and that the problem is the nature of this type of decorator. This seems very similar to the use case in #104 and #92. Specifically, I think #92 (comment) is the problem.

@aviraldg
Copy link
Contributor

I'm facing a related problem (I think.) With the cursor before the @ below, adding a character inserts it after the @:

screenshot from 2016-06-15 00-32-45

As you'd guess, the actual content here is just "@aviraldg:matrix.org testing"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants