-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Decouple "zoom/scaling the canvas" from zoom out mode (without mode rename) #65482
base: trunk
Are you sure you want to change the base?
Conversation
# Conflicts: # packages/block-editor/src/components/block-tools/zoom-out-toolbar.js # packages/block-editor/src/components/tool-selector/index.js # packages/block-editor/src/store/reducer.js # packages/edit-site/src/components/global-styles/screen-style-variations.js # packages/editor/src/components/visual-editor/index.js
# Conflicts: # packages/block-editor/src/hooks/use-zoom-out.js
# Conflicts: # packages/editor/src/components/editor-interface/index.js
export function zoomLevel( state = 100, action ) { | ||
switch ( action.type ) { | ||
case 'SET_ZOOM_OUT': | ||
return action.zoom; | ||
case 'RESET_ZOOM': | ||
return 100; | ||
} | ||
|
||
return state; | ||
} | ||
|
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.
Let's make the nomenclature consistent. Is it "zoom-out" or "zoom-level"? type
and naming need to be consistent.
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.
Zoom out is anytime zoom level is less than 1.
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.
It's usually best to avoid using floating point numbers in JS. I went for 100
to mirror the traditional zoom scale of 0-100.
Is there a reason why you are suggesting 1
? Is it used somewhere else already?
export function getZoomLevel( state ) { | ||
return state.zoomLevel; | ||
} | ||
|
||
/** | ||
* Returns whether the editor is considered zoomed out. | ||
* | ||
* @param {Object} state Global application state. | ||
* @return {boolean} Whether the editor is zoomed. | ||
*/ | ||
export function isZoomOut( state ) { | ||
return getZoomLevel( state ) < 100; | ||
} |
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.
Let's make the nomenclature consistent. Is it "zoom-out" or "zoom-level"? type
and naming need to be consistent.
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 think this is all right, zoom out is any zoom level less than 1.
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.
See #65482 (comment)
* A hook used to set the editor mode to zoomed out mode, invoking the hook sets the mode. | ||
* A hook used to set the zoomed out view, invoking the hook sets the mode. |
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.
This hook used to set the mode to zoom-out
. Now it just sets the zoom level. Is that what we want? It's only used in a single location in Core.
Personally I think it should be deprecated as an API.
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.
Don't we need the hook for all the effect management it does?
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 guess it could be useful for "zooming the canvas". But note how it's usage has already changed from managing "modes" to managing "scale". It's just a premature API in my opinion.
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. |
Size Change: +535 B (+0.03%) Total Size: 1.77 MB
ℹ️ View Unchanged
|
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 think this is great! Nomenclature wise I think "zoom out" is fine as a syntactic sugar for zoom level less than 1. It is a bit confusing that the mode which affects editing and selection is also called zoom out but since that is likely to be deprecated maybe it's fine?
Bug In this PR the Global Styles > Browse styles is better than trunk in that selection is default but the canvas is zoomed out. However, clicking exits the zoomed out view.
export function getZoomLevel( state ) { | ||
return state.zoomLevel; | ||
} | ||
|
||
/** | ||
* Returns whether the editor is considered zoomed out. | ||
* | ||
* @param {Object} state Global application state. | ||
* @return {boolean} Whether the editor is zoomed. | ||
*/ | ||
export function isZoomOut( state ) { | ||
return getZoomLevel( state ) < 100; | ||
} |
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 think this is all right, zoom out is any zoom level less than 1.
* A hook used to set the editor mode to zoomed out mode, invoking the hook sets the mode. | ||
* A hook used to set the zoomed out view, invoking the hook sets the mode. |
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.
Don't we need the hook for all the effect management it does?
export function zoomLevel( state = 100, action ) { | ||
switch ( action.type ) { | ||
case 'SET_ZOOM_OUT': | ||
return action.zoom; | ||
case 'RESET_ZOOM': | ||
return 100; | ||
} | ||
|
||
return state; | ||
} | ||
|
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.
Zoom out is anytime zoom level is less than 1.
This is a strange bug. I ruled out Update: one of the |
@draganescu I've normalised everything towards "level" for consistency and to disambiguate it from I also reduced some complexity where I was able. |
What?
Decouples concept of "zooming the canvas" from "composing with patterns".
In this PR we retain
zoom-out
as the mode name.Alternative to #65265
Why?
See #65265
How?
See #65265
Only difference is that we do not rename the mode - it remains
zoom-out
.Testing Instructions
Same as #65265
Testing Instructions for Keyboard
Screenshots or screencast