Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support exiting Code block with triple enter and remove legacy code for WP<6.1 #786

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions inc/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,22 +210,8 @@ function init(): void {

if ( $block instanceof WP_Block_Type ) {
register_editor_assets( $block );

if ( property_exists( $block, 'editor_script_handles' ) ) {
// As of WP>=6.1.
$block->editor_script_handles[] = EDITOR_SCRIPT_HANDLE;
} else {
/* @noinspection PhpUndefinedFieldInspection */
$block->editor_script = EDITOR_SCRIPT_HANDLE;
}

if ( property_exists( $block, 'editor_style_handles' ) ) {
// As of WP>=6.1.
$block->editor_style_handles[] = EDITOR_STYLE_HANDLE;
} else {
/* @noinspection PhpUndefinedFieldInspection */
$block->editor_style = EDITOR_STYLE_HANDLE;
}
$block->editor_script_handles[] = EDITOR_SCRIPT_HANDLE;
$block->editor_style_handles[] = EDITOR_STYLE_HANDLE;
}
}

Expand Down
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"devDependencies": {
"@wordpress/api-fetch": "6.43.0",
"@wordpress/block-editor": "12.14.0",
"@wordpress/blocks": "12.23.0",
"@wordpress/components": "25.12.0",
"@wordpress/editor": "13.23.0",
"@wordpress/element": "5.23.0",
Expand Down
27 changes: 0 additions & 27 deletions phpstan-baseline.php

This file was deleted.

1 change: 0 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ includes:
# @see https://github.com/phpstan/phpstan-src/blob/b9f62d63f2deaa0a5e97f51073e41a422c48aa01/conf/bleedingEdge.neon
- phar://phpstan.phar/conf/bleedingEdge.neon
- vendor/szepeviktor/phpstan-wordpress/extension.neon
- phpstan-baseline.php
parameters:
level: 9
paths:
Expand Down
18 changes: 15 additions & 3 deletions src/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
PanelBody,
PanelRow,
} from '@wordpress/components';
import { createBlock, getDefaultBlockName } from '@wordpress/blocks';

/**
* External dependencies
Expand Down Expand Up @@ -110,7 +111,13 @@ const parseHighlightedLines = (highlightedLines) => {
return highlightedLinesSet;
};

export default function CodeEdit({ attributes, setAttributes, onRemove }) {
export default function CodeEdit({
attributes,
setAttributes,
onRemove,
insertBlocksAfter,
mergeBlocks,
}) {
const blockProps = useBlockProps();

const updateLanguage = (language) => {
Expand Down Expand Up @@ -138,16 +145,21 @@ export default function CodeEdit({ attributes, setAttributes, onRemove }) {
);

const richTextProps = {
// These RichText props must mirror core <https://github.com/WordPress/gutenberg/blob/a42fd75/packages/block-library/src/code/edit.js#L12-L19>.
// These RichText props must mirror core <https://github.com/WordPress/gutenberg/blob/e95bb8c9530bbdef1db623eca11b80bd73493197/packages/block-library/src/code/edit.js#L19-L31>.
...{
tagName: 'code',
identifier: 'content',
value: attributes.content,
onChange: (content) => setAttributes({ content }),
onRemove,
onMerge: mergeBlocks,
placeholder: __('Write code…'),
'aria-label': __('Code'),
preserveWhiteSpace: true,
__unstablePastePlainText: true, // See <https://github.com/WordPress/gutenberg/pull/27236>.
__unstableOnSplitAtDoubleLineEnd: () => {
insertBlocksAfter(createBlock(getDefaultBlockName()));
},
},

// Additional props unique to HighlightableTextArea.
Expand Down Expand Up @@ -231,7 +243,7 @@ export default function CodeEdit({ attributes, setAttributes, onRemove }) {
</PanelRow>
</PanelBody>
</InspectorControls>
{/* Keep in sync with https://github.com/WordPress/gutenberg/blob/a42fd75/packages/block-library/src/code/edit.js#L10-L21 */}
{/* Keep in sync with https://github.com/WordPress/gutenberg/blob/e95bb8c9530bbdef1db623eca11b80bd73493197/packages/block-library/src/code/edit.js#L17 */}
<pre {...blockProps}>
<HighlightableTextArea {...richTextProps} />
</pre>
Expand Down