Repository navigation
Editor: Keep the canvas height stable while resizing the canvas #81163
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4442b75
Editor: Keep the canvas height stable while resizing the canvas
t-hamano f4cc690
Editor: Drop redundant comments in the visual editor canvas sizing
t-hamano 44fb5e4
Editor: Always fill the editor height instead of a device aspect ratio
t-hamano 9670e97
Editor: Scale the canvas height with its width instead of always filling
t-hamano 9d92b0f
Merge branch 'trunk' into fix/canvas-height-during-resize
t-hamano e9a4096
Merge branch 'trunk' into fix/canvas-height-during-resize
t-hamano 42e8847
Editor: Remove unused blockEditorStore import from private selectors …
t-hamano 9e1fafe
Editor: Remove unused onResizeStart and onResizeStop props from Resiz…
t-hamano 55fd27d
Editor: Add unit tests for the visual editor getCanvasHeight helper
t-hamano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/editor/src/components/visual-editor/test/get-canvas-height.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import { getCanvasHeight } from '../index'; | ||
|
|
||
| describe( 'getCanvasHeight', () => { | ||
| it( 'fills the available height at the full container width', () => { | ||
| expect( getCanvasHeight( 1000, { width: 1000, height: 800 } ) ).toBe( | ||
| 800 | ||
| ); | ||
| } ); | ||
|
|
||
| it( 'uses the target 9:16 aspect ratio at the minimum canvas width', () => { | ||
| // 300 / ( 9 / 16 ) = 533.33, rounded to 533. | ||
| expect( getCanvasHeight( 300, { width: 1000, height: 800 } ) ).toBe( | ||
| 533 | ||
| ); | ||
| } ); | ||
|
|
||
| it( 'interpolates between the container and target aspect ratios in between', () => { | ||
| // Halfway between 300 and 1000, so halfway between the container ratio | ||
| // ( 1.25 ) and the target ratio ( 0.5625 ): 650 / 0.90625 = 717.24. | ||
| expect( getCanvasHeight( 650, { width: 1000, height: 800 } ) ).toBe( | ||
| 717 | ||
| ); | ||
| } ); | ||
|
|
||
| it( 'grows with the canvas width', () => { | ||
| const heights = [ 300, 500, 700, 900 ].map( ( width ) => | ||
| getCanvasHeight( width, { width: 1000, height: 800 } ) | ||
| ); | ||
| expect( heights ).toEqual( [ 533, 659, 733, 781 ] ); | ||
| } ); | ||
|
|
||
| it( 'never exceeds the available height', () => { | ||
| // In a short container, the 9:16 height of 533 is clamped to 300. | ||
| expect( getCanvasHeight( 300, { width: 1000, height: 300 } ) ).toBe( | ||
| 300 | ||
| ); | ||
| } ); | ||
|
|
||
| it( 'clamps widths outside the resizable range', () => { | ||
| // Wider than the container: the container aspect ratio applies, and the | ||
| // height is capped at the container height. | ||
| expect( getCanvasHeight( 1200, { width: 1000, height: 800 } ) ).toBe( | ||
| 800 | ||
| ); | ||
| // Narrower than the minimum width: the target aspect ratio applies. | ||
| expect( getCanvasHeight( 200, { width: 1000, height: 800 } ) ).toBe( | ||
| 356 | ||
| ); | ||
| } ); | ||
| } ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 looks like these two props were introduced recently in #80553; do we need to keep them around now that we're not using them anymore?
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.
Nice catch, fixed in 9e1fafe. Since
ResizableEditoris a private component, we can safely remove those props.