From 535e0752051957f3e6ab7aca2e71e99ceffc9a6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ella=20Van=C2=A0Durpe?= Date: Fri, 1 Mar 2019 13:41:12 +0100 Subject: [PATCH] RichText: fix wordwise selection on Windows (#14184) * RichText: fix wordwise selection on Windows * Fix crtl ctrl typo. * Add docs --- packages/editor/src/components/rich-text/index.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/editor/src/components/rich-text/index.js b/packages/editor/src/components/rich-text/index.js index ccfe32326d944f..d6be0a622307ee 100644 --- a/packages/editor/src/components/rich-text/index.js +++ b/packages/editor/src/components/rich-text/index.js @@ -573,13 +573,14 @@ export class RichText extends Component { /** * Handles a keydown event. * - * @param {KeyboardEvent} event The keydown event. + * @param {SyntheticEvent} event A synthetic keyboard event. */ onKeyDown( event ) { - const { keyCode, shiftKey, altKey, metaKey } = event; + const { keyCode, shiftKey, altKey, metaKey, ctrlKey } = event; if ( - ! shiftKey && ! altKey && ! metaKey && + // Only override left and right keys without modifiers pressed. + ! shiftKey && ! altKey && ! metaKey && ! ctrlKey && ( keyCode === LEFT || keyCode === RIGHT ) ) { this.handleHorizontalNavigation( event ); @@ -661,6 +662,13 @@ export class RichText extends Component { } } + /** + * Handles horizontal keyboard navigation when no modifiers are pressed. The + * navigation is handled separately to move correctly around format + * boundaries. + * + * @param {SyntheticEvent} event A synthetic keyboard event. + */ handleHorizontalNavigation( event ) { const value = this.createRecord(); const { formats, text, start, end } = value;