Conversation
d069e99 to
5f16dca
Compare
|
Seeing an error on splitting: Otherwise I think this is looking nice. |
editor/store/actions.js
Outdated
| * @return {Object} Action object. | ||
| */ | ||
| export function replaceBlocks( uids, blocks ) { | ||
| export function replaceBlocks( uids, blocks, blockToSelectUid ) { |
There was a problem hiding this comment.
This looks good to me but would love to know what @youknowriad thinks. :)
| { ...block, layout } | ||
| ) ); | ||
| replaceBlocks( [ ownProps.uid ], blocks ); | ||
| replaceBlocks( [ ownProps.uid ], blocks, blockToSelectUid ); |
There was a problem hiding this comment.
Why don't we just call selectBlock or something like that right after? It seems weird to tie the replacement of blocks with selection?
There was a problem hiding this comment.
Now the action object contains the property selectBlock, unfortunately, I was not able to use it in the parameter name because we already have a function with that name.
There was a problem hiding this comment.
I think you misunderstood my remark here. For me we shouldn't add this new parameter here and just call another action right after selectBlock( blockToSelectUid ).
There was a problem hiding this comment.
Hi @youknowriad I missed your suggestion at first but now I updated the code to follow it :)
| get( action.blocks, [ 0, 'uid' ], null ); | ||
|
|
||
| return { | ||
| ...state, |
There was a problem hiding this comment.
I know it was already the case before but I feel the REPLACE_BLOCKS action should not touch the selection at all unless the currently selected block is being replaced.
There was a problem hiding this comment.
Hi @youknowriad, that's exactly the current behavior. We have a condition at the start that guarantees that if the currently selected block is not replaced we don't change the selection:
if ( action.uids.indexOf( state.start ) === -1 ) {
return state;
}
| } | ||
| const replaceArrayStart = before ? | ||
| [ createBlock( name, { ...attributes, content: before } ) ] : | ||
| []; |
There was a problem hiding this comment.
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.
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.
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.
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.
5f16dca to
7cc2438
Compare
|
Hi @iseulde,
I added some checks that should avoid this error, thank you for catching it. @iseulde @youknowriad, thank you for the reviews the feedback was addressed. |
7cc2438 to
0004562
Compare
editor/components/rich-text/index.js
Outdated
| rect = getRectangleFromRange( this.editor.selection.getRng() ); | ||
| } | ||
| const focusPosition = this.getFocusPosition( rect ); | ||
| if ( ! focusPosition ) { |
editor/components/rich-text/index.js
Outdated
| */ | ||
| getFocusPosition( position ) { | ||
| // if the node was removed or replaced return immediately. | ||
| if ( ! this.containerRef.current ) { |
There was a problem hiding this comment.
I'm surprised this even happens. Maybe worth finding out the root cause of this and comment. It might even be the same as #6981.
There was a problem hiding this comment.
It was not related to #6981 I added it was a patch and it did not fix the problem here. But now that we reuse the UID this problem does not happen and all the changes to TinyMCE here reverted.
|
@jorgefilipecosta Have you tried this? #6964 (comment) I think that would make the code a bit cleaner too. :) |
0004562 to
9272fd5
Compare
| } | ||
|
|
||
| onReplace( blocks ) { | ||
| onReplace( blocks, blockToSelect ) { |
There was a problem hiding this comment.
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?
|
Is this still desired to be continued? Is it better represented in the alternative proposal discussed in #8119 ? |
|
Closing this in favor of #8119. |
Description
Splitting was not a single operation but two operations insert blocks + setAttributes. That made undo behave in a strange way.
In this PR we make onSplit a single operation using onReplace (props to @iseulde for this idea).
onReplace by default selects the first block. That was not what we wanted in this use case so a new prop was added that allows choosing the bock we want to select.
To accomplish this onReplace was changed to not clone the blocks because cloning changes the UID.
I think we should remove clone from onReplace anyway even if we find an alternative approach to the PR. When a user asks for some blocks to be replaced I think the expectation is that the new blocks the user set are the used ones and the UID's saved in the state are the same that the user passed. In PR #6325 I felt the same need and I applied the same change to onReplace.
We did not added more test cases yet if we find this approach something we want to pursue I will add them.
How has this been tested?
Add a paragraph write some text, press enter in the middle, see the paragraphs were divided. Press undo see that undo works as expected and the paragraphs are joined again.
Try to do some testing to verify removing clone fro onReplace does not cause unexpected behaviors.
Screenshots
Before:


After: