Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use diff of prev/next marker's markups instead of assuming consistent order #52

Merged
merged 1 commit into from
Aug 10, 2015

Conversation

bantic
Copy link
Collaborator

@bantic bantic commented Aug 10, 2015

fixes #51

Using bulk edit actions (like applying/unapplying markups to a range of selected markers) could make the order of markups on contiguous markers get out of sync. Marker 1 has ['B', 'I'] and Marker 2 has ['I', 'B'], e.g. The current code that finds opened and closed markups on a marker assumes that the markups array will always be in the same order. This PR changes that to look at the difference of the two arrays rather than the slice of the current array up to the matching item in the prev/next marker's markups.

mixonic added a commit that referenced this pull request Aug 10, 2015
Use diff of prev/next marker's markups instead of assuming consistent order
@mixonic mixonic merged commit ff2a9c6 into master Aug 10, 2015
@mixonic mixonic deleted the markup-order-independence branch August 10, 2015 16:00
@ErisDS
Copy link
Contributor

ErisDS commented Aug 10, 2015

Just out of interest - has any thought been given to enforcing a consistent order for markup in mobiledoc? It's locked down/strict in other ways, it may make sense to lock this down too?

The comment here made me think of https://medium.com/medium-eng/why-contenteditable-is-terrible-122d8a40e480

@gpoitch
Copy link
Member

gpoitch commented Aug 10, 2015

Pre-mobiledoc, the parser sorted the markups so they were always in the same order

@mixonic
Copy link
Contributor

mixonic commented Aug 10, 2015

When we translate markup ranges into DOM nodes, we sort them by type: A, then STRONG, then EM. We will never print a STRONG tag containing an anchor. We break it up so that the anchor contains the STRONG tag.

The internal data-structure is agnostic, but the mobiledoc renderer would currently base output on the leading tag.

For example on content like:

Hello Google

We would generate:

Marker: Hello
  opens: `b`
  closes: nothing
Marker: Google
  opens: `a`
  closes: `a`, `b`

The proposal of that ending paragraph is that we do this instead:

Marker: Hello
  opens: `b`
  closes: `b`
Marker: Google
  opens: `a`, `b`
  closes: `b`, `a`

I think this matters for medium b/c they are parsing the DOM after you edit it- We rarely look at the DOM as authoritative, and regardless we may render something different that what was parsed. For example, if you had three b tags in a row and we parsed that, the rendered mobiledoc would contain only a single b tag spanning all three text nodes.

tl;dr I'm unsure we need to enforce this for any architectural reason.

@gpoitch
Copy link
Member

gpoitch commented Aug 10, 2015

Yup, not a huge deal since dom isn't authoritative. A case for it could be if you toggle on/off a couple of markups. Visually there could be no change, but if the order of the markups in the mobiledoc changed you now have an unnecessary dirty node / post revision.

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

Successfully merging this pull request may close these issues.

allow marker markups to be order-independent
4 participants