Skip to content

Conversation

@YoranBrondsema
Copy link
Collaborator

@YoranBrondsema YoranBrondsema commented Jul 16, 2019

Changes

Fix #689

The idea is that when toggling a section, we maintain a list of mappings from the original to the new section. Sometimes, sections are maintained but the tag name is simply modified. This happens for instance when going from a paragraph to a H1. However, sometimes sections are destroyed and a new one is created. For instance, when going from a list to a paragraph.

By looking at the mapping of old section to new section, we can reconstruct the selection after toggling:

mobiledoc-kit

The only edge case is when toggling to a list. There, the sections in the range have to point to ListItem's rather than ListSections. But at the time of toggling, we only have access to the ListSection, and we don't know which ListItem's the new range should point to.

mobiledoc-kit

Other changes

  1. Remove redundant CSS from demo.css
  2. Add a button in the demo to toggle a quote

if (sectionTransformations.length) {
let changedHeadSection = sectionTransformations
.find(({ from }) => { return from === range.headSection; })
.to;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this was described to me as: Walk through the changes, find the mapping which is for the same section as the old range's head, then use the mapped "to" as the new section for the head.

This seems good and like it might be a useful pattern in refactoring the range code in general.

@YoranBrondsema
Copy link
Collaborator Author

@mixonic Just realized that we didn't merge this and didn't include it in the pre-release. Are you cool merging this and then publishing a new pre-release?

@ZeeJab ZeeJab merged commit 39a82d7 into bustle:master Sep 20, 2019
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.

Original range should be remembered after toggleSection

3 participants