Skip to content

Commit

Permalink
Allow editing existing footnote from formats toolbar (#52506)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcsf authored Jul 11, 2023
1 parent 664223f commit a508633
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions packages/block-library/src/footnotes/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,30 @@ export const format = {
} = useSelect( blockEditorStore );
const { selectionChange, insertBlock } =
useDispatch( blockEditorStore );

function onClick() {
registry.batch( () => {
const id = createId();
const newValue = insertObject(
value,
{
type: formatName,
attributes: {
'data-fn': id,
let id;
if ( isObjectActive ) {
const object = value.replacements[ value.start ];
id = object?.attributes?.[ 'data-fn' ];
} else {
id = createId();
const newValue = insertObject(
value,
{
type: formatName,
attributes: {
'data-fn': id,
},
innerHTML: `<a href="#${ id }" id="${ id }-link">*</a>`,
},
innerHTML: `<a href="#${ id }" id="${ id }-link">*</a>`,
},
value.end,
value.end
);
newValue.start = newValue.end - 1;

onChange( newValue );
value.end,
value.end
);
newValue.start = newValue.end - 1;
onChange( newValue );
}

// BFS search to find the first footnote block.
let fnBlock = null;
Expand Down

0 comments on commit a508633

Please sign in to comment.