-
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
Writing flow: remove first empty paragraph on Backspace #61889
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
insertBlocks( | ||
replacement, | ||
getBlockIndex( _clientId ), | ||
targetRootClientId, | ||
changeSelection | ||
); | ||
removeBlock( firstClientId, false ); | ||
} else { | ||
switchToDefaultOrRemove(); |
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'll add a test for the site editor as well.
Size Change: +52 B (0%) Total Size: 1.75 MB
ℹ️ View Unchanged
|
Flaky tests detected in 3f2127a. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9203635910
|
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.
Thanks for the ping! This is an interesting one.
When it comes to backspace, my expectation was that it moves the caret up a line, and when we're in the first position within the list of blocks, backspace doing nothing feels a bit more correct to me (it works that way in Google Docs for example). In order to remove the first line, I'd reach for the delete key rather than backspace, as the action we're performing applies to what follows from the current caret position rather than what precedes.
I notice that in both trunk and this PR, if I press delete from the first line, there's a focus loss, so the focus is no longer within the editor canvas:
2024-05-31.12.22.37.mp4
Would it be worth fixing that up in this PR, or in a separate one? I imagine it's a case of using the selectBlock( nextBlockClientId );
logic again somewhere?
In this PR, when using the backspace key, the focus is correctly preserved within the editor canvas:
2024-05-31.12.24.12.mp4
So, from my perspective I have a very weakly held opinion that I slightly prefer the behaviour on trunk. Since this PR exists, though, I imagine this is a feature folks have requested, or a pain point that's been encountered?
The code change looks good to me — I'm not terribly familiar with this part of the code, but it makes sense to me. It looks like the else
conditions are slightly more permissive than beforehand, but from the looks of it that's intentional.
As we're close to the beta freeze, I think if this is a desired feature it's worth trying and the added test coverage gives me confidence, along with the fact that it's testing as expected in the post and site editors, so I'll give this the ✅.
It might be worth getting a second review, though, if there's any doubt about it!
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 tested it on Windows OS and it works as expected.
I notice that in both trunk and this PR, if I press delete from the first line, there's a focus loss, so the focus is no longer within the editor canvas:
I was able to reproduce this issue too. It might not be necessary to address it in this PR, but perhaps we could make the following changes, for example?
diff --git a/packages/block-editor/src/components/block-list/block.js b/packages/block-editor/src/components/block-list/block.js
index 030d08b42c..5e191af76b 100644
--- a/packages/block-editor/src/components/block-list/block.js
+++ b/packages/block-editor/src/components/block-list/block.js
@@ -453,7 +453,11 @@ const applyWithDispatch = withDispatch( ( dispatch, ownProps, registry ) => {
if ( getBlockOrder( nextBlockClientId ).length ) {
moveFirstItemUp( nextBlockClientId, false );
} else {
+ const block = getBlock( clientId );
mergeBlocks( clientId, nextBlockClientId );
+ if ( isUnmodifiedDefaultBlock( block ) ) {
+ selectBlock( nextBlockClientId );
+ }
}
} else {
@andrewserong Since it's in trunk I can do a follow-up. Let's merge this so we have it in the release. |
What?
Allows you to remove the first paragraph in the editor (or post content) with Backspace.
Why?
Currently it's impossible to remove the first paragraph with Backspace, you'd have to click the delete button in the options menu.
How?
Extends the block merging behaviour.
Testing Instructions
See e2e test.
Testing Instructions for Keyboard
Screenshots or screencast