Skip to content

Commit ab589b3

Browse files
jorgefilipecostat-hamanoyouknowriadntsekourasmrwweb
authored
Fix: Safari "Edit as HTML" for Fit Text deletes content (WordPress#74864)
* Fix: Safari "Edit as HTML" for Stretchy Text block variations deletes content. * performance optimization * bug fix Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: youknowriad <youknowriad@git.wordpress.org> Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org> Co-authored-by: mrwweb <mrwweb@git.wordpress.org>
1 parent dc3ebdb commit ab589b3

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

packages/block-editor/src/hooks/fit-text.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,25 @@ function useFitText( { fitText, name, clientId } ) {
6868
const hasFitTextSupport = hasBlockSupport( name, FIT_TEXT_SUPPORT_KEY );
6969
const blockElement = useBlockElement( clientId );
7070

71-
// Monitor block attribute changes, and parent changes.
71+
// Monitor block attribute changes, parent changes, and block mode.
7272
// Any attribute or parent change may change the available space.
73-
const { blockAttributes, parentId } = useSelect(
73+
// Block mode is needed to disable fit text when in HTML editing mode.
74+
const { blockAttributes, parentId, blockMode } = useSelect(
7475
( select ) => {
7576
if ( ! clientId || ! hasFitTextSupport || ! fitText ) {
7677
return EMPTY_OBJECT;
7778
}
79+
const _blockMode =
80+
select( blockEditorStore ).getBlockMode( clientId );
81+
if ( _blockMode === 'html' ) {
82+
return { blockMode: _blockMode };
83+
}
7884
return {
7985
blockAttributes:
8086
select( blockEditorStore ).getBlockAttributes( clientId ),
8187
parentId:
8288
select( blockEditorStore ).getBlockRootClientId( clientId ),
89+
blockMode: _blockMode,
8390
};
8491
},
8592
[ clientId, hasFitTextSupport, fitText ]
@@ -118,7 +125,8 @@ function useFitText( { fitText, name, clientId } ) {
118125
! fitText ||
119126
! blockElement ||
120127
! clientId ||
121-
! hasFitTextSupport
128+
! hasFitTextSupport ||
129+
blockMode === 'html'
122130
) {
123131
return;
124132
}
@@ -189,11 +197,17 @@ function useFitText( { fitText, name, clientId } ) {
189197
applyFitText,
190198
blockElement,
191199
hasFitTextSupport,
200+
blockMode,
192201
] );
193202

194203
// Trigger fit text recalculation when content changes
195204
useEffect( () => {
196-
if ( fitText && blockElement && hasFitTextSupport ) {
205+
if (
206+
fitText &&
207+
blockElement &&
208+
hasFitTextSupport &&
209+
blockMode !== 'html'
210+
) {
197211
// Wait for next frame to ensure DOM has updated after content changes
198212
const frameId = window.requestAnimationFrame( () => {
199213
if ( blockElement ) {
@@ -209,6 +223,7 @@ function useFitText( { fitText, name, clientId } ) {
209223
applyFitText,
210224
blockElement,
211225
hasFitTextSupport,
226+
blockMode,
212227
] );
213228

214229
return { fontSize };

0 commit comments

Comments
 (0)