From 094b13720d2e7720dad9c358fc35b4f82b2e381c Mon Sep 17 00:00:00 2001 From: Miguel Fonseca <150562+mcsf@users.noreply.github.com> Date: Tue, 11 Jul 2023 11:18:19 +0100 Subject: [PATCH] Remove footnote from RichText toolbar if already present --- packages/block-library/src/footnotes/format.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/footnotes/format.js b/packages/block-library/src/footnotes/format.js index 40de6a132ea99..0c46f9ec14c7d 100644 --- a/packages/block-library/src/footnotes/format.js +++ b/packages/block-library/src/footnotes/format.js @@ -8,7 +8,7 @@ import { v4 as createId } from 'uuid'; */ import { __ } from '@wordpress/i18n'; import { formatListNumbered as icon } from '@wordpress/icons'; -import { insertObject } from '@wordpress/rich-text'; +import { remove, insertObject } from '@wordpress/rich-text'; import { RichTextToolbarButton, store as blockEditorStore, @@ -40,7 +40,13 @@ export const format = { } = useSelect( blockEditorStore ); const { selectionChange, insertBlock } = useDispatch( blockEditorStore ); + function onClick() { + if ( isObjectActive ) { + onChange( remove( value, value.start, value.end ) ); + return; + } + registry.batch( () => { const id = createId(); const newValue = insertObject(