Skip to content

Code Editor: Content changes not respected when using mode change keyboard shortcut #9512

@aduth

Description

@aduth

Describe the bug

When making a change to the post content in the Code Editor and retaining focus within the Code Editor's textarea, switching back to Visual Editor reveals that the changes were not applied if the change in editor modes is applied using the keyboard shortcut.

To Reproduce

  1. Navigate to Posts > Add New
  2. (Prerequisite) Switch to Code Editor if not already
  3. Enter text in the Code Editor textarea
  4. Without leaving the field, press the keyboard combination to switch editor modes (⇧⌥⌘M)
  5. Note that your changes made in Step 3 are not shown.

Expected behavior

Changes made in Step 3 are shown in Visual Editor.

Additional context

This is due to the PostTextEditor component's "delayed sync" behavior, where we do not parse on individual keypresses, only when the user "finishes editing". The current metric for determining that a user has finished their edits is the blur event. But within this workflow, the blur event is not triggered (or at least not handled by PostTextEditor, perhaps due to the fact that it will have unmounted by the time it's called).

A possible fix may be to consider whether there are unsaved changes in the PostTextEditor's componentWillUnmount and invoking the onPersist prop.

Metadata

Metadata

Assignees

Labels

Needs DevReady for, and needs developer efforts[Feature] Code EditorHandling the code view of the editing experience[Type] BugAn existing feature does not function as intended

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions