Skip to content

Commit

Permalink
AI Assistant: Fix block inserter behavior when Breve is enabled (#38483)
Browse files Browse the repository at this point in the history
* move md5 check out of tree preparation

* changelog
  • Loading branch information
dhasilva authored Jul 23, 2024
1 parent 89b9dac commit 4c6c1d6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

AI Assistant: Fix block inserter behavior when Breve is enabled
Original file line number Diff line number Diff line change
Expand Up @@ -248,28 +248,31 @@ export function registerBreveHighlights() {
interactive: false,
edit: () => {},
...configSettings,
__experimentalGetPropsForEditableTreePreparation( _select, { blockClientId } ) {
__experimentalGetPropsForEditableTreePreparation() {
return {
isProofreadEnabled: (
globalSelect( 'jetpack/ai-breve' ) as BreveSelect
).isProofreadEnabled(),
currentMd5: ( globalSelect( 'jetpack/ai-breve' ) as BreveSelect ).getBlockMd5(
formatName,
blockClientId
),
isFeatureEnabled: ( globalSelect( 'jetpack/ai-breve' ) as BreveSelect ).isFeatureEnabled(
config.name
),
};
},
__experimentalCreatePrepareEditableTree(
{ isProofreadEnabled, isFeatureEnabled, currentMd5 },
{ isProofreadEnabled, isFeatureEnabled },
{ blockClientId, richTextIdentifier }
) {
return ( formats: Array< RichTextFormatList >, text: string ) => {
const record = { formats, text } as RichTextValue;
const type = formatName;

// Has to be defined here, as adding it to __experimentalGetPropsForEditableTreePreparation
// causes an issue with the block inserter. ref p1721746774569699-slack-C054LN8RNVA
const currentMd5 = ( globalSelect( 'jetpack/ai-breve' ) as BreveSelect ).getBlockMd5(
formatName,
blockClientId
);

if ( text && isProofreadEnabled && isFeatureEnabled ) {
const block = globalSelect( 'core/block-editor' ).getBlock( blockClientId );
const blockContent = getBlockContent( block );
Expand Down

0 comments on commit 4c6c1d6

Please sign in to comment.