-
Notifications
You must be signed in to change notification settings - Fork 150
Toggle list type sections #248
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
Conversation
src/js/editor/post.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can happen in the walkMarkerableSections above- the array sectionsToChange seems to not serve any logical function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At one point there was an issue with mutation while walking — a section's next would get reassigned and the walkMarkerableSections callback would skip sections. I will try removing this and see if the tests still pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed it and tests are still 🍏, seems good
|
Was there a bug of note in the linked list implementation? |
The heuristic for detecting if an item is already in a list doesn't cover every case. In particular, an item can be the only item in another list, in which case its |
8903110 to
5824fb9
Compare
5824fb9 to
8b69ace
Compare
|
@mixonic This is ready for another review when you have a chance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So eager to change all these cursor.offsets :-D
* marked `changeSectionTagName` private in favor of `toggleSection`.
'ember-mobiledoc-editor' uses `changeSectionTagName` so it will need
to be updated
* join contiguous list sections -- when a section adjacent to a
list section is removed, the postEditor will scan for and join
contiguous list sections in the before_complete queue
* put cursor position at start of changed range -- the end of the
range is not stable (it can move around when joinin contiguous lists
or when the toggle changes the last section to/from a list item) so
it is quite difficult to select the entire range after the toggle.
* remove unused `splitAtListItem`, `splitIntoSections` methods on
ListSection, ListItem
* add `MarkupSection.isMarkupSection` property
* add Section `canJoin`, `join` methods
* add test to ensure toggling while on a card section is a no-op
* Add editor#selectRange, postEditor#setRange APIs
* Remove Cursor `moveToSection`, `selectSections`, `moveToPosition`
* use `Cursor#selectRange` primarily, instead (called by `editor#selectRange`)
* Add Range.fromSection convenience method
* Remove `Editor#moveToPosition` (in favor of `selectRange`)
fixes #186
18676f9 to
1e47433
Compare
Add
postEditor#toggleSection,postEditor#setRange,editor#selectRangeAPIstoggleSectionis list-section and list-item aware and will toggle a markup section to/from a list item. Toggling a markup section that is adjacent to a list will join it with that list. Toggling a list item will turn it into a markup section and separate it from the before/after list section. The postEditor run loop will join contiguous list sections of the same type during the before_complete callback queue. This means that deleting a markup section that was between two lists will also cause the lists to be joined together.There is some internal refactoring of the cursor movement/selection methods. It is possible that a postEditor method returns a position that has a
sectionproperty that is no longer part of the post abstract after the postEditor'srun()finishes. This can happen when a markup section is turned into a listSection+listItem and then (in the before_complete queue) merged with an adjacent list.As a result, it is no longer always safe to use a returned
Positionwith a call to one of the cursor movement methods oneditor.cursor(e.g. moveToPosition/selectRange/selectSection). ThepostEditor#setRangemethod is added to handle this case.Mutation methods on the postEditor that could destroy/detach a section can now introspect the current range and update it if they are removing/changing a section that is part of the active
range. ThepostEditor#_joinContiguousListSectionsis the only method that does this so far, but eventually all of the methods should be updated to update an active range when necessary. The postEditor automatically renders the updated range at the end of its run loop ifpostEditor#setRangewas called.This is ready for review and merge. If this looks good I will update the documentation to reflect the new APIs shortly before/after merging.
Possible breaking changes
cursor:selectSections,moveToSection,moveToPosition. None of these was explicitly marked as public.editor#moveToPosition. This was not explicitly public beforeeditor#moveToSection, but this API did not actually exist (it should have beeneditor.cursor.moveToSection). After merge I'll fix up this part of the readmefixes #186