jpuri / jpuri/draftjs-utils

handleNewLine does not produce the right undo stack when breaking out of a block

Open
#11 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
286
Forks
46
PR merge metrics
No merged PRs in 30d

Description

This is best demonstrated with a GIF:

https://jsfiddle.net/thibaudcolas/Lo2zL37h/

draftjs-utils-newline-undo-stack

Here I'm pressing return once and then undoing it with ctrl + Z, but it takes two undo operations to get back to the pre-newline state.

The problem is that after insertNewUnstyledBlock produces the split-block change, removeSelectedBlocksStyle makes a change-block-type. This should be a single operation.

It might be enough to use Modifier.setBlockType(content, selection, 'unstyled') directly in insertNewUnstyledBlock. I'm happy to try and make a PR doing this.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior using the linked jsfiddle, then inspect handleNewLine, insertNewUnstyledBlock, and removeSelectedBlocksStyle. Trace the split-block and change-block-type changes around a return in a block. Done means one undo operation returns the editor to its pre-newline state.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.