From 8465ece2b6a0d330737821f189e41e31ddd86715 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Thu, 13 Jun 2024 10:16:53 +0200 Subject: [PATCH] re-use getNewIndexFromPresets --- .../src/components/global-styles/font-sizes.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/packages/edit-site/src/components/global-styles/font-sizes.js b/packages/edit-site/src/components/global-styles/font-sizes.js index e5addf9bf58c0..5fd6da5206c61 100644 --- a/packages/edit-site/src/components/global-styles/font-sizes.js +++ b/packages/edit-site/src/components/global-styles/font-sizes.js @@ -20,15 +20,7 @@ import { unlock } from '../../lock-unlock'; const { useGlobalSetting } = unlock( blockEditorPrivateApis ); import Subtitle from './subtitle'; import { NavigationButtonAsItem } from './navigation-button'; - -function getAvailableIndex( sizes ) { - // Filter the slug field that ends with custom-{number}. - const indexes = sizes.map( ( size ) => { - const match = size.slug.match( /custom-(\d+)$/ ); - return match ? parseInt( match[ 1 ], 10 ) : 0; - } ); - return Math.max( ...indexes ) + 1; -} +import { getNewIndexFromPresets } from './utils'; function FontSizes() { const [ fontSizes, setFontSizes ] = useGlobalSetting( @@ -39,7 +31,7 @@ function FontSizes() { const sizes = fontSizes.theme ?? fontSizes.default; const handleAddFontSize = () => { - const index = getAvailableIndex( sizes ); + const index = getNewIndexFromPresets( sizes, 'custom-' ); const newFontSize = { /* translators: %d: font size index */ name: sprintf( __( 'New Font Size %d' ), index ),