Skip to content

Commit

Permalink
Force the selection when composition is resolved (#2094)
Browse files Browse the repository at this point in the history
Summary:
Fixes facebookarchive/draft-js#2093.
Pull Request resolved: facebookarchive/draft-js#2094

Reviewed By: claudiopro

Differential Revision: D21770987

Pulled By: mrkev

fbshipit-source-id: f198a89ce2eae69328daa5ce917085ce0d726dba
  • Loading branch information
robbertbrak authored and facebook-github-bot committed Jul 2, 2020
1 parent 919721a commit 8c39789
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ 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');
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`.
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 8c39789

Please sign in to comment.