From 9eddb3614c11b29c1e0e4a4eeff7903ad0d76cf4 Mon Sep 17 00:00:00 2001 From: "Matthew Riley MacPherson (tofumatt)" Date: Thu, 28 Jun 2018 17:07:27 +0100 Subject: [PATCH] chore: Move TINYMCE_ZERO_WIDTH_SPACE to keycodes and expand name --- editor/components/rich-text/index.js | 26 ++++++++++++-------------- packages/keycodes/src/index.js | 10 ++++++++++ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/editor/components/rich-text/index.js b/editor/components/rich-text/index.js index feda0ae90840f..b4740533bc237 100644 --- a/editor/components/rich-text/index.js +++ b/editor/components/rich-text/index.js @@ -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'; @@ -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 @@ -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; } /** @@ -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(); } } diff --git a/packages/keycodes/src/index.js b/packages/keycodes/src/index.js index f5ab3ea87ce13..6e0d2d444e9f1 100644 --- a/packages/keycodes/src/index.js +++ b/packages/keycodes/src/index.js @@ -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. *