Skip to content

Block Editor: move selection state from RichText to the store#14640

Merged
ellatrix merged 3 commits intomasterfrom
try/block-editor-selection-state
Apr 19, 2019
Merged

Block Editor: move selection state from RichText to the store#14640
ellatrix merged 3 commits intomasterfrom
try/block-editor-selection-state

Conversation

@ellatrix
Copy link
Copy Markdown
Member

@ellatrix ellatrix commented Mar 26, 2019

Description

Fixes #11616.
Blocks #11005 and #12002. Blocks making RichText a controlled component.

This is an attempt to move local RichText selection state to block-editor store.

RichText would have the following props:

  • selectionStart: the selection start offset, similar to the textarea attrubute.
  • selectionEnd: the selection end offset, similar to the textarea attrubute.
  • onSelectionChange: the function that will be called when the selection changes.

Within blocks, this state is provided by context. Nothing changes for block authors.

In the block-editor store, the selection state will now include a rich text identifier and offset in addition to the block client ID.

Why?

  • This will be needed if we ever want to read/write selection in RichText areas. Think:
  • Blocks making RichText a controlled component. This PR moves logic to set the caret position to the MERGE_BLOCKS action and removes it from RichText.

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.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Package] Block editor /packages/block-editor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove local RichText state in favor of global selection state

7 participants