Skip to content

Commit

Permalink
RichText: Fix delete key in empty contenteditables (#5348)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored Mar 2, 2018
1 parent f1d96b3 commit efc5945
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function gutenberg_register_scripts_and_styles() {
wp_register_script(
'wp-utils',
gutenberg_url( 'utils/build/index.js' ),
array(),
array( 'tinymce-latest' ),
filemtime( gutenberg_dir_path() . 'utils/build/index.js' )
);
wp_register_script(
Expand Down
9 changes: 8 additions & 1 deletion utils/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import { includes } from 'lodash';
import tinymce from 'tinymce';

/**
* Browser dependencies
Expand Down Expand Up @@ -57,8 +58,14 @@ export function isHorizontalEdge( container, isReverse, collapseRanges = false )
}

const maxOffset = node.nodeType === TEXT_NODE ? node.nodeValue.length : node.childNodes.length;
const editor = tinymce.get( node.id );

if ( ! isReverse && offset !== maxOffset ) {
if (
! isReverse &&
offset !== maxOffset &&
// content editables with only a BR element are considered empty
( ! editor || ! editor.dom.isEmpty( node ) )
) {
return false;
}

Expand Down

0 comments on commit efc5945

Please sign in to comment.