Skip to content

Commit

Permalink
chore: Move TINYMCE_ZERO_WIDTH_SPACE to keycodes and expand name
Browse files Browse the repository at this point in the history
  • Loading branch information
tofumatt committed Jun 28, 2018
1 parent a34c471 commit 9eddb36
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
26 changes: 12 additions & 14 deletions editor/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ import {
getScrollContainer,
} from '@wordpress/dom';
import { createBlobURL } from '@wordpress/blob';
import { BACKSPACE, DELETE, ENTER, LEFT, RIGHT, rawShortcut } from '@wordpress/keycodes';
import {
BACKSPACE,
DELETE,
ENTER,
LEFT,
RIGHT,
TINYMCE_ZERO_WIDTH_SPACE,
rawShortcut,
} from '@wordpress/keycodes';
import { withInstanceId, withSafeTimeout, Slot } from '@wordpress/components';
import { withSelect } from '@wordpress/data';
import { rawHandler } from '@wordpress/blocks';
Expand All @@ -50,16 +58,6 @@ import TokenUI from './tokens/ui';

const { Node } = window;

/**
* Zero-width space character used by TinyMCE as a caret landing point for
* inline boundary nodes.
*
* @see tinymce/src/core/main/ts/text/Zwsp.ts
*
* @type {string}
*/
const TINYMCE_ZWSP = '\uFEFF';

/**
* Returns true if the node is the inline node boundary. This is used in node
* filtering prevent the inline boundary from being included in the split which
Expand All @@ -74,7 +72,7 @@ const TINYMCE_ZWSP = '\uFEFF';
*/
export function isEmptyInlineBoundary( node ) {
const text = node.nodeName === 'A' ? node.innerText : node.textContent;
return text === TINYMCE_ZWSP;
return text === TINYMCE_ZERO_WIDTH_SPACE;
}

/**
Expand Down Expand Up @@ -478,11 +476,11 @@ export class RichText extends Component {
// only be exempt when focusNode is not _only_ the ZWSP, which occurs
// when caret is placed on the right outside edge of inline boundary.
if ( ! isReverse && focusOffset === nodeValue.length &&
nodeValue.length > 1 && nodeValue[ 0 ] === TINYMCE_ZWSP ) {
nodeValue.length > 1 && nodeValue[ 0 ] === TINYMCE_ZERO_WIDTH_SPACE ) {
offset = 0;
}

if ( nodeValue[ offset ] === TINYMCE_ZWSP ) {
if ( nodeValue[ offset ] === TINYMCE_ZERO_WIDTH_SPACE ) {
event.stopPropagation();
}
}
Expand Down
10 changes: 10 additions & 0 deletions packages/keycodes/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ export const CTRL = 'ctrl';
export const COMMAND = 'meta';
export const SHIFT = 'shift';

/**
* Zero-width space character used by TinyMCE as a caret landing point for
* inline boundary nodes.
*
* @see tinymce/src/core/main/ts/text/Zwsp.ts
*
* @type {string}
*/
export const TINYMCE_ZERO_WIDTH_SPACE = '\uFEFF';

/**
* Return true if platform is MacOS.
*
Expand Down

0 comments on commit 9eddb36

Please sign in to comment.