Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/WordPress/gutenberg into …
Browse files Browse the repository at this point in the history
…rnmobile/danilo-try-to-fix-undo-redo

* 'master' of https://github.com/WordPress/gutenberg:
  Avoid changing default wpautop priority (#11722)
  Try fixing the tab navigation issue (#12390)
  Polish editor style documentation (#12381)
  • Loading branch information
daniloercoli committed Nov 29, 2018
2 parents 7766b5c + 2a66db0 commit c0748b5
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 30 deletions.
16 changes: 15 additions & 1 deletion docs/designers-developers/developers/themes/theme-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ This flag will make sure users are only able to choose colors from the `editor-c

Gutenberg supports the theme's [editor styles](https://codex.wordpress.org/Editor_Style), however it works a little differently than in the classic editor.

In the classic editor, the editor stylesheet is loaded directly into the iframe of the WYSIWYG editor, with no changes. Gutenberg, however, doesn't use iframes. To make sure your styles are applied only to the content of the editor, we automatically transform your editor styles by selectively rewriting or adjusting certain CSS selectors.
In the classic editor, the editor stylesheet is loaded directly into the iframe of the WYSIWYG editor, with no changes. Gutenberg, however, doesn't use iframes. To make sure your styles are applied only to the content of the editor, we automatically transform your editor styles by selectively rewriting or adjusting certain CSS selectors. This also allows Gutenberg to leverage your editor style in block variation previews.

For example, if you write `body { ... }` in your editor style, this is rewritten to `.editor-styles-wrapper { ... }`. This also means that you should _not_ target any of the editor class names directly.

Because it works a little differently, you need to opt-in to this by adding an extra snippet to your theme, in addition to the add_editor_style function:

Expand All @@ -212,6 +214,8 @@ add_theme_support('editor-styles');

You shouldn't need to change your editor styles too much; most themes can add the snippet above and get similar results in the classic editor and inside Gutenberg.

### Dark backgrounds

If your editor style relies on a dark background, you can add the following to adjust the color of the UI to work on dark backgrounds:

```php
Expand All @@ -221,6 +225,16 @@ add_theme_support( 'dark-editor-style' );

Note you don't need to add `add_theme_support( 'editor-styles' );` twice, but that rule does need to be present for the `dark-editor-style` rule to work.

### Enqueuing the editor style

To make sure your editor style is loaded and parsed correctly, enqueue it using the following method:

```php
add_editor_style( 'style-editor.css' );
```

It is enough to paste that in your `functions.php` file, for the style to be loaded and parsed.

### Basic colors

You can style the editor like any other webpage. Here's how to change the background color and the font color to blue:
Expand Down
29 changes: 29 additions & 0 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ function gutenberg_render_block( $block ) {
* @return string Updated post content.
*/
function do_blocks( $content ) {
// If there are blocks in this content, we shouldn't run wpautop() on it later.
$priority = has_filter( 'the_content', 'wpautop' );
if ( false !== $priority && doing_filter( 'the_content' ) && has_blocks( $content ) ) {
remove_filter( 'the_content', 'wpautop', $priority );
add_filter( 'the_content', '_restore_wpautop_hook', $priority + 1 );
}

$blocks = gutenberg_parse_blocks( $content );
$output = '';

Expand All @@ -187,6 +194,28 @@ function do_blocks( $content ) {
add_filter( 'the_content', 'do_blocks', 7 ); // BEFORE do_shortcode() and oembed.
}

if ( ! function_exists( '_restore_wpautop_hook' ) ) {
/**
* If do_blocks() needs to remove wpautop() from the `the_content` filter,
* this re-adds it afterwards, for subsequent `the_content` usage.
*
* @access private
*
* @since 4.6.0
*
* @param string $content The post content running through this filter.
* @return string The unmodified content.
*/
function _restore_wpautop_hook( $content ) {
$current_priority = has_filter( 'the_content', '_restore_wpautop_hook' );

add_filter( 'the_content', 'wpautop', $current_priority - 1 );
remove_filter( 'the_content', '_restore_wpautop_hook', $current_priority );

return $content;
}
}

if ( ! function_exists( 'strip_dynamic_blocks' ) ) {
/**
* Remove all dynamic blocks from the given content.
Expand Down
17 changes: 0 additions & 17 deletions lib/compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,6 @@ function gutenberg_add_rest_nonce_to_heartbeat_response_headers( $response ) {
}
add_filter( 'wp_refresh_nonces', 'gutenberg_add_rest_nonce_to_heartbeat_response_headers' );

/**
* As a substitute for the default content `wpautop` filter, applies autop
* behavior only for posts where content does not contain blocks.
*
* @param string $content Post content.
* @return string Paragraph-converted text if non-block content.
*/
function gutenberg_wpautop( $content ) {
if ( has_blocks( $content ) ) {
return $content;
}

return wpautop( $content );
}
remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'gutenberg_wpautop', 6 );

/**
* Check if we need to load the block warning in the Classic Editor.
*
Expand Down
12 changes: 0 additions & 12 deletions packages/editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,18 +682,6 @@ export class RichText extends Component {
this.savedContent = value;
}

// If blocks are merged, but the content remains the same, e.g. merging
// an empty paragraph into another, then also set the selection to the
// end.
if ( isSelected && ! prevProps.isSelected && ! this.isActive() ) {
const record = this.formatToValue( value );
const prevRecord = this.formatToValue( prevProps.value );
const length = getTextContent( prevRecord ).length;
record.start = length;
record.end = length;
this.applyRecord( record );
}

// If any format props update, reapply value.
const shouldReapply = Object.keys( this.props ).some( ( name ) => {
if ( name.indexOf( 'format_' ) !== 0 ) {
Expand Down
3 changes: 3 additions & 0 deletions packages/editor/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,9 @@ export function blockSelection( state = {
// If there is replacement block(s), assign first's client ID as
// the next selected block. If empty replacement, reset to null.
const nextSelectedBlockClientId = get( action.blocks, [ 0, 'clientId' ], null );
if ( nextSelectedBlockClientId === state.start && nextSelectedBlockClientId === state.end ) {
return state;
}

return {
...state,
Expand Down
19 changes: 19 additions & 0 deletions packages/editor/src/store/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1761,6 +1761,25 @@ describe( 'state', () => {
} );
} );

it( 'should not replace the selected block if we keep it when replacing blocks', () => {
const original = deepFreeze( { start: 'chicken', end: 'chicken' } );
const state = blockSelection( original, {
type: 'REPLACE_BLOCKS',
clientIds: [ 'chicken' ],
blocks: [
{
clientId: 'chicken',
name: 'core/freeform',
},
{
clientId: 'wings',
name: 'core/freeform',
} ],
} );

expect( state ).toBe( original );
} );

it( 'should reset if replacing with empty set', () => {
const original = deepFreeze( { start: 'chicken', end: 'chicken' } );
const state = blockSelection( original, {
Expand Down

0 comments on commit c0748b5

Please sign in to comment.