From 3be4d372f6848be4a0d285ec05f0bdb4a4562ced Mon Sep 17 00:00:00 2001 From: Robbert Brak Date: Thu, 2 Jul 2020 15:36:57 -0700 Subject: [PATCH] Force the selection when composition is resolved (#2094) Summary: Fixes https://github.com/facebook/draft-js/issues/2093. Pull Request resolved: https://github.com/facebook/draft-js/pull/2094 Reviewed By: claudiopro Differential Revision: D21770987 Pulled By: mrkev fbshipit-source-id: f198a89ce2eae69328daa5ce917085ce0d726dba --- .../composition/DraftEditorCompositionHandler.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/component/handlers/composition/DraftEditorCompositionHandler.js b/src/component/handlers/composition/DraftEditorCompositionHandler.js index 8b459d347c..e5f6d1d721 100644 --- a/src/component/handlers/composition/DraftEditorCompositionHandler.js +++ b/src/component/handlers/composition/DraftEditorCompositionHandler.js @@ -18,6 +18,7 @@ const DraftModifier = require('DraftModifier'); const DraftOffsetKey = require('DraftOffsetKey'); const EditorState = require('EditorState'); const Keys = require('Keys'); +const UserAgent = require('UserAgent'); const editOnSelect = require('editOnSelect'); const getContentEditableContainer = require('getContentEditableContainer'); @@ -25,6 +26,8 @@ const getDraftEditorSelection = require('getDraftEditorSelection'); const getEntityKeyForSelection = require('getEntityKeyForSelection'); const nullthrows = require('nullthrows'); +const isIE = UserAgent.isBrowser('IE'); + /** * Millisecond delay to allow `compositionstart` to fire again upon * `compositionend`. @@ -225,10 +228,14 @@ const DraftEditorCompositionHandler = { editor.restoreEditorDOM(); - const editorStateWithUpdatedSelection = EditorState.acceptSelection( - editorState, - compositionEndSelectionState, - ); + // See: + // - https://github.com/facebook/draft-js/issues/2093 + // - https://github.com/facebook/draft-js/pull/2094 + // Apply this fix only in IE for now. We can test it in + // other browsers in the future to ensure no regressions + const editorStateWithUpdatedSelection = isIE + ? EditorState.forceSelection(editorState, compositionEndSelectionState) + : EditorState.acceptSelection(editorState, compositionEndSelectionState); editor.update( EditorState.push(