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

Reset selection after undo/redo #15133

Closed
wants to merge 1 commit into from
Closed

Reset selection after undo/redo #15133

wants to merge 1 commit into from

Conversation

ellatrix
Copy link
Member

@ellatrix ellatrix commented Apr 23, 2019

Description

This is a WIP!

I'm trying to solve #12002 and #12327, but it touches some things that I'm not so sure about.

The goals is to include selection state in history record so that it can be restored. The basic idea seems to work more or less, but the expectations around restoring selection after undo seem a bit different than what you would think: the very last selection change should be restored, not the selection of the last snapshot.

I try to explain.

  1. You open a post => initial present, say [ { value: '' } ].
  2. You place the caret somewhere => even though there is no content change, present is expected to update with the new selection, say [ { value: '', selection: 0 } ].
  3. You insert some text => the present is updated again, no history is added, say { past: [ { value: '', selection: 0 } ], present: [ { value: 'test', selection: 4 } ] }
  4. A second passes => the last changes are marked as persistent, say { past: [ { value: '', selection: 0 }, { value: 'test', selection: 4 } ], present: [ { value: 'test', selection: 4 } ] }
  5. You undo the last change => you expect the caret to be right where it was before typing, say [ { value: '', selection: 0 } ].

This probably means that selection should be continuously passed up to the editor module (even if no content changes). There, simple selection change should not create an undo level, of course. But a content change right after a simple selection change should (but not a content change after content change).

This would be similar to how it is done in TinyMCE: the bookmark is stored before a change is made:

https://github.com/tinymce/tinymce/blob/1b4c8329a55788e3b5201b1b4df4539cb3397b7d/src/core/main/ts/api/UndoManager.ts#L196-L206

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 changed the title WIP Reset selection after undo/redo Apr 24, 2019
@ellatrix ellatrix added the [Status] In Progress Tracking issues with work in progress label Apr 24, 2019
@ellatrix
Copy link
Member Author

Superseded by #16428.

@ellatrix ellatrix closed this Jul 10, 2019
@ellatrix ellatrix deleted the try/undo-selection branch July 10, 2019 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] In Progress Tracking issues with work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant