-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix undo on paragraph split #6964
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
import { isFinite, find, omit } from 'lodash'; | ||
import { isFinite, find, last, omit } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
|
@@ -84,7 +84,7 @@ class ParagraphBlock extends Component { | |
this.setFontSize = this.setFontSize.bind( this ); | ||
} | ||
|
||
onReplace( blocks ) { | ||
onReplace( blocks, blockToSelect ) { | ||
const { attributes, onReplace } = this.props; | ||
onReplace( blocks.map( ( block, index ) => ( | ||
index === 0 && block.name === name ? | ||
|
@@ -93,9 +93,10 @@ class ParagraphBlock extends Component { | |
...attributes, | ||
...block.attributes, | ||
}, | ||
uid: this.props.id, | ||
} : | ||
block | ||
) ) ); | ||
) ), blockToSelect ); | ||
} | ||
|
||
toggleDropCap() { | ||
|
@@ -236,14 +237,12 @@ class ParagraphBlock extends Component { | |
if ( after ) { | ||
blocks.push( createBlock( name, { content: after } ) ); | ||
} | ||
const replaceArrayStart = before ? | ||
[ createBlock( name, { ...attributes, content: before } ) ] : | ||
[]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a subtle difference here with the previous behavior. We're creating a new block with a new UID which resets all other properties of the blocks and cause a remount instead of a rerender. Maybe it's fine, just noting. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's true we change the uid and we have a remount but I think doing that is ok. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we reuse the block that is being replaced in the reducer if the name is the same? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We had already an onReplace in the paragraph with logic to reuse attribute when replacing with the same block I added one line there that also reuses the UID. I think it simplifies the things and removes the need for any TinyMCE hacks. |
||
|
||
insertBlocksAfter( blocks ); | ||
|
||
if ( before ) { | ||
setAttributes( { content: before } ); | ||
} else { | ||
onReplace( [] ); | ||
} | ||
const newBlocks = replaceArrayStart.concat( blocks ); | ||
this.onReplace( newBlocks, newBlocks.length > 1 ? last( newBlocks ).uid : undefined ); | ||
} : | ||
undefined | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this change only being applied to the paragraph block. Should it be generalised to all blocks that have an
onSplit
prop, such as headings?