Skip to content

Commit 30cc1d3

Browse files
committed
fix: only cofirm when font family is changed
1 parent 1384c6e commit 30cc1d3

File tree

1 file changed

+19
-6
lines changed
  • src/plugins/global-settings/typography

1 file changed

+19
-6
lines changed

src/plugins/global-settings/typography/index.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
328328
}
329329

330330
updateTypography( newSettings )
331-
332331
return newSettings
333332
} )
334333
}
@@ -372,15 +371,29 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
372371
return false
373372
}
374373

375-
const getIsChangeConfirmed = () => {
374+
const getIsFontPairChangeConfirmed = () => {
376375
// No need to confirm when the current font pair is custom
377376
// since changes are saved
378377
if ( customFontPairs.find( fontPair => fontPair.name === selectedFontPairName ) ) {
379378
return true
380379
}
381380

381+
// The confirmation should only occur if the font family has been edited
382+
// since selecting font pair only changes font family
383+
const currentFontPair = getCurrentFontPair()
382384
const isDirty = TYPOGRAPHY_TAGS.some( ( { selector } ) => {
383-
return getIsAllowReset( selector )
385+
if ( isEditingFontPair || ! currentFontPair ) {
386+
return false
387+
}
388+
const fontPairStyle = currentFontPair.typography[ selector ]
389+
const typographyStyle = typographySettings[ selector ]
390+
391+
if ( ! Array.isArray( typographyStyle ) &&
392+
fontPairStyle.fontFamily &&
393+
fontPairStyle.fontFamily !== typographyStyle.fontFamily ) {
394+
return true
395+
}
396+
return false
384397
} )
385398

386399
if ( isDirty ) {
@@ -455,7 +468,7 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
455468
fontPair={ FONT_PAIRS[ 0 ] }
456469
isSelected={ selectedFontPairName === FONT_PAIRS[ 0 ].name }
457470
onClick={ () => {
458-
if ( ! getIsChangeConfirmed() ) {
471+
if ( ! getIsFontPairChangeConfirmed() ) {
459472
return
460473
}
461474
updateSelectedFontPair( FONT_PAIRS[ 0 ].name )
@@ -467,7 +480,7 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
467480
customFontPairs={ customFontPairs }
468481
selected={ selectedFontPairName }
469482
onClick={ ( name, typography ) => {
470-
if ( ! getIsChangeConfirmed() ) {
483+
if ( ! getIsFontPairChangeConfirmed() ) {
471484
return
472485
}
473486
updateSelectedFontPair( name )
@@ -486,7 +499,7 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
486499
fontPair={ fontPair }
487500
isSelected={ selectedFontPairName === fontPair.name }
488501
onClick={ () => {
489-
if ( ! getIsChangeConfirmed() ) {
502+
if ( ! getIsFontPairChangeConfirmed() ) {
490503
return
491504
}
492505
updateSelectedFontPair( fontPair.name )

0 commit comments

Comments
 (0)