Fix #689: Original range should be remembered after toggleSection
#690
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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.
Other changes