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

Record selection changes in history (undo) #16428

Closed
wants to merge 11 commits into from

Conversation

ellatrix
Copy link
Member

@ellatrix ellatrix commented Jul 5, 2019

Description

Creates selection reducers in core/editor to track selection within the withHistory reducer.

I've also split isSelectionEnabled, isMultiSelecting, and initialPosition out of the blockSelection, as these are not tied to the selection state. Since the reducer then didn't contain anything but the start and end of the selection, I flattened the structure to state.selectionStart and state.selectionEnd. The reducers ended up being much simpler.

The following gif shows the result after two times undo:

undo-selection

How has this been tested?

Screenshots

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

@ellatrix ellatrix force-pushed the try/blocks-selection-history branch from 41f4892 to 7315f25 Compare July 5, 2019 11:16
@ellatrix ellatrix added the [Package] Block editor /packages/block-editor label Jul 5, 2019
@ellatrix ellatrix added the [Feature] History History, undo, redo, revisions, autosave. label Jul 5, 2019
@ellatrix ellatrix changed the title Block Editor: record selection changes in history Record selection changes in history (undo) Jul 5, 2019
@ellatrix ellatrix added the [Package] Editor /packages/editor label Jul 5, 2019
@ellatrix ellatrix requested review from nerrad and ntwb as code owners July 5, 2019 13:40
@ellatrix ellatrix added the Good First Review A PR that's suitable for someone looking to contribute for the first time by reviewing code label Jul 5, 2019
@ellatrix ellatrix added this to the Gutenberg 6.1 milestone Jul 5, 2019
packages/block-editor/src/store/reducer.js Outdated Show resolved Hide resolved
packages/editor/src/store/reducer.js Outdated Show resolved Hide resolved
packages/block-editor/src/store/selectors.js Outdated Show resolved Hide resolved
packages/block-editor/src/store/reducer.js Outdated Show resolved Hide resolved
@ellatrix ellatrix force-pushed the try/blocks-selection-history branch 4 times, most recently from 6e691f5 to a95e3f0 Compare July 10, 2019 14:06
@ellatrix ellatrix mentioned this pull request Jul 10, 2019
5 tasks
@ellatrix ellatrix force-pushed the try/blocks-selection-history branch from 32d03bf to ee24ec0 Compare July 18, 2019 09:39
@ellatrix ellatrix force-pushed the try/blocks-selection-history branch from f5d17c1 to 0b74a1d Compare August 8, 2019 16:52
@ellatrix

This comment has been minimized.

@ellatrix

This comment has been minimized.

@ellatrix ellatrix force-pushed the try/blocks-selection-history branch from 0b74a1d to 9886d9f Compare August 9, 2019 14:59
@ellatrix
Copy link
Member Author

ellatrix commented Aug 9, 2019

Phew, this passed now! It was not obvious from the errors what the cause was, but apparently it was resetting the selection when the provider didn't provide any selection, which is the case for previews. :)

@ellatrix ellatrix requested a review from mcsf August 9, 2019 17:00
@ellatrix
Copy link
Member Author

ellatrix commented Aug 9, 2019

So this is again ready for a final review.

@gziolo gziolo removed this from the Gutenberg 6.3 milestone Aug 12, 2019
@ellatrix ellatrix added this to the Gutenberg 6.4 milestone Aug 19, 2019
@gziolo gziolo removed this from the Gutenberg 6.4 milestone Aug 27, 2019
Copy link
Contributor

@epiqueras epiqueras left a comment

Choose a reason for hiding this comment

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

Since #16932 was merged, we'll need to take a different approach here.

I think it should be pretty easy to make the selection a transient edit of the post entity just like .blocks:

transientEdits: { blocks: true },

This makes them part of undo behavior, but not considered for change detection or persistence.

We can probably still keep all of the other changes that simplify the reducer.

@ellatrix
Copy link
Member Author

@epiqueras Thanks for letting me know. What's the best place I can learn about the changes? I'll have a look through the code changes soon.

@ellatrix
Copy link
Member Author

ellatrix commented Oct 7, 2019

Closing in favour of #17824.

@ellatrix ellatrix closed this Oct 8, 2019
@ellatrix ellatrix deleted the try/blocks-selection-history branch October 8, 2019 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] History History, undo, redo, revisions, autosave. [Feature] Writing Flow Block selection, navigation, splitting, merging, deletion... [Package] Block editor /packages/block-editor [Package] Editor /packages/editor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants