diff --git a/src/blocks.js b/src/blocks.js index 5ee0cae..092e66e 100644 --- a/src/blocks.js +++ b/src/blocks.js @@ -69,6 +69,11 @@ registerBlockType( 'syntaxhighlighter/code', { type: 'boolean', default: syntaxHighlighterData.settings.makeURLsClickable.default, }, + + quickCode: { + type: 'boolean', + default: syntaxHighlighterData.settings.quickCode.default, + }, }, supports: { @@ -128,7 +133,8 @@ registerBlockType( 'syntaxhighlighter/code', { firstLineNumber, highlightLines, wrapLines, - makeURLsClickable + makeURLsClickable, + quickCode } = attributes; let blockSettingRows = []; @@ -250,6 +256,24 @@ registerBlockType( 'syntaxhighlighter/code', { ); } + // Quick code + if ( syntaxHighlighterData.settings.quickCode.supported ) { + blockSettingRows.push( + wp.element.createElement( + PanelRow, + null, + wp.element.createElement( + ToggleControl, + { + label: __( 'Enable edit mode on double click', 'syntaxhighlighter' ), + checked: quickCode, + onChange: ( quickCode ) => setAttributes( { quickCode } ), + } + ) + ) + ); + } + const blockSettings = ( diff --git a/syntaxhighlighter.php b/syntaxhighlighter.php index a5fff1b..33ffb5e 100644 --- a/syntaxhighlighter.php +++ b/syntaxhighlighter.php @@ -104,6 +104,7 @@ function_exists( 'parse_blocks' ) // WordPress 5.0+ 'tabsize' => 4, 'toolbar' => 0, 'wraplines' => 1, // 2.x only + 'quickcode' => 1, // 3.x only ) ); // Create the settings array by merging the user's settings and the defaults @@ -358,6 +359,10 @@ function enqueue_block_editor_assets() { 'supported' => true, 'default' => (bool) $this->settings['autolinks'], ), + 'quickCode' => (object) array( + 'supported' => ( '3' == $this->settings['shversion'] ), + 'default' => (bool) $this->settings['quickcode'], + ), ); wp_add_inline_script( @@ -496,6 +501,7 @@ public function render_block( $attributes, $content ) { 'highlightLines' => 'highlight', 'wrapLines' => 'wraplines', 'makeURLsClickable' => 'autolinks', + 'quickCode' => 'quickcode', ); foreach ( $remaps as $from => $to ) { @@ -1038,6 +1044,9 @@ function maybe_output_scripts() { if ( 1 != $this->settings['wraplines'] ) echo " SyntaxHighlighter.defaults['wrap-lines'] = false;\n"; + if ( 1 != $this->settings['quickcode'] ) + echo " SyntaxHighlighter.defaults['quick-code'] = false;\n"; + ?> SyntaxHighlighter.all(); // Infinite scroll support @@ -1114,6 +1123,7 @@ function shortcode_callback( $atts, $code = '', $tag = false ) { 'title' => $this->settings['title'], 'toolbar' => false, 'wraplines' => false, + 'quickcode' => false, ), $atts ) ); // Check for language shortcode tag such as [php]code[/php] @@ -1171,6 +1181,7 @@ function shortcode_callback( $atts, $code = '', $tag = false ) { 'smarttabs' => 'smart-tabs', 'tabsize' => 'tab-size', 'wraplines' => 'wrap-lines', + 'quickcode' => 'quick-code', ); // Allowed configuration parameters and their type @@ -1191,6 +1202,7 @@ function shortcode_callback( $atts, $code = '', $tag = false ) { 'title' => 'other', 'toolbar' => 'boolean', 'wrap-lines' => 'boolean', + 'quick-code' => 'boolean', ) ); $title = ''; @@ -1324,7 +1336,7 @@ function settings_page() { ?>
-

+

@@ -1333,7 +1345,7 @@ function settings_page() { ?> - + - + - +

-
- +
+
- - + +
-

+

-

+

- + - + - + - + - + - +
- - -
-
-
-
-
-
-
- + + +
+
+
+
+
+
+
+
+

- +
@@ -1454,9 +1467,9 @@ function settings_page() { ?>
-

+

-

+

echo '

'; ?> -

+

true', '1', 'false', '0' ); ?>

-

+

maybe_output_scripts(); ?> @@ -1553,6 +1567,7 @@ function validate_settings( $settings ) { $settings['smarttabs'] = ( ! empty($settings['smarttabs']) ) ? 1 : 0; $settings['toolbar'] = ( ! empty($settings['toolbar']) ) ? 1 : 0; // May be overridden below $settings['wraplines'] = ( ! empty($settings['wraplines']) ) ? 1 : 0; // 2.x only for now + $settings['quickcode'] = ( ! empty($settings['quickcode']) ) ? 1 : 0; // 3.x only for now // If the version changed, then force change the toolbar version setting if ( $settings['shversion'] != $this->settings['shversion'] ) {