@@ -58,18 +58,25 @@ function useFitText( { fitText, name, clientId } ) {
5858 const hasFitTextSupport = hasBlockSupport ( name , FIT_TEXT_SUPPORT_KEY ) ;
5959 const blockElement = useBlockElement ( clientId ) ;
6060
61- // Monitor block attribute changes, and parent changes.
61+ // Monitor block attribute changes, parent changes, and block mode .
6262 // Any attribute or parent change may change the available space.
63- const { blockAttributes, parentId } = useSelect (
63+ // Block mode is needed to disable fit text when in HTML editing mode.
64+ const { blockAttributes, parentId, blockMode } = useSelect (
6465 ( select ) => {
6566 if ( ! clientId || ! hasFitTextSupport || ! fitText ) {
6667 return EMPTY_OBJECT ;
6768 }
69+ const _blockMode =
70+ select ( blockEditorStore ) . getBlockMode ( clientId ) ;
71+ if ( _blockMode === 'html' ) {
72+ return { blockMode : _blockMode } ;
73+ }
6874 return {
6975 blockAttributes :
7076 select ( blockEditorStore ) . getBlockAttributes ( clientId ) ,
7177 parentId :
7278 select ( blockEditorStore ) . getBlockRootClientId ( clientId ) ,
79+ blockMode : _blockMode ,
7380 } ;
7481 } ,
7582 [ clientId , hasFitTextSupport , fitText ]
@@ -107,7 +114,8 @@ function useFitText( { fitText, name, clientId } ) {
107114 ! fitText ||
108115 ! blockElement ||
109116 ! clientId ||
110- ! hasFitTextSupport
117+ ! hasFitTextSupport ||
118+ blockMode === 'html'
111119 ) {
112120 return ;
113121 }
@@ -178,11 +186,17 @@ function useFitText( { fitText, name, clientId } ) {
178186 applyFitText ,
179187 blockElement ,
180188 hasFitTextSupport ,
189+ blockMode ,
181190 ] ) ;
182191
183192 // Trigger fit text recalculation when content changes
184193 useEffect ( ( ) => {
185- if ( fitText && blockElement && hasFitTextSupport ) {
194+ if (
195+ fitText &&
196+ blockElement &&
197+ hasFitTextSupport &&
198+ blockMode !== 'html'
199+ ) {
186200 // Wait for next frame to ensure DOM has updated after content changes
187201 const frameId = window . requestAnimationFrame ( ( ) => {
188202 if ( blockElement ) {
@@ -198,6 +212,7 @@ function useFitText( { fitText, name, clientId } ) {
198212 applyFitText ,
199213 blockElement ,
200214 hasFitTextSupport ,
215+ blockMode ,
201216 ] ) ;
202217}
203218
0 commit comments