-
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
Zoom Out: Always go to edit mode when inserting a single block #64169
Conversation
Size Change: +45 B (0%) Total Size: 1.76 MB
ℹ️ View Unchanged
|
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. |
@@ -49,5 +49,5 @@ export function useZoomOut( zoomOut = true ) { | |||
) { | |||
__unstableSetEditorMode( originalEditingMode.current ); | |||
} | |||
}, [ __unstableSetEditorMode, zoomOut, mode ] ); | |||
}, [ __unstableSetEditorMode, zoomOut ] ); |
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.
Needed to stop zoom out from being triggered again.
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.
We can't omit dependencies from this array as it can cause unexpected side effects.
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.
Can you explain the conditions you were testing under that "triggered [zoom out] again"?
I've refactored the code so that the mode
is not a required dependency but I'd like to verify this behaves as intended.
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 like this behaviour. It feels right and there is clear user intent. I think we should try and land this.
Aside: I think with many of these types of interactions where we trying to infer user intent, we will only truly know whether it works when it's tested with lots of users.
// Let inserting a single block always trigger Edit mode. | ||
if ( | ||
action.type === 'INSERT_BLOCKS' && | ||
action.blocks.length === 1 && | ||
action.blocks[ 0 ].innerBlocks.length === 0 | ||
) { | ||
return 'edit'; | ||
} | ||
|
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'm noting that in the line above the behaviour is conditionalised to navigation
mode.
gutenberg/packages/block-editor/src/store/reducer.js
Lines 1799 to 1803 in 54269c0
export function editorMode( state = 'edit', action ) { | |
// Let inserting block in navigation mode always trigger Edit mode. | |
if ( action.type === 'INSERT_BLOCKS' && state === 'navigation' ) { | |
return 'edit'; | |
} |
This action will apply to all modes in all editors. Are we confident that's safe? Would it be better to limit the action to be in Zoom Out mode only?
// Let inserting a single block always trigger Edit mode. | |
if ( | |
action.type === 'INSERT_BLOCKS' && | |
action.blocks.length === 1 && | |
action.blocks[ 0 ].innerBlocks.length === 0 | |
) { | |
return 'edit'; | |
} | |
// Let inserting a single block always trigger Edit mode. | |
if ( | |
state === 'zoom-out' && // only applies in zoom out mode | |
action.type === 'INSERT_BLOCKS' && | |
action.blocks.length === 1 && | |
action.blocks[ 0 ].innerBlocks.length === 0 | |
) { | |
return 'edit'; | |
} | |
@scruffian Do we still want to pursue this? |
I think there's still something useful in this idea, but I'm trying something else in #65286. |
What?
Switch to edit mode (i.e. close zoom out mode or navigation mode) when inserting a single block.
Why?
When users get dropped into Zoom Out mode (for example in #61489) this drops them back into normal editing mode without them needing to find the zoom out controls.
How?
Update the
editorMode
reducer to respond toINSERT_BLOCKS
.Testing Instructions
Enable zoomed out view when selecting a pattern category in the main inserter.
experiment.Screenshots or screencast
Screen.Recording.2024-08-01.at.16.04.03.mov