From ea1419ff7810448c305ea92905fb0ddfab9fa73f Mon Sep 17 00:00:00 2001 From: Aviral Dasgupta Date: Wed, 21 Sep 2016 07:02:53 +0530 Subject: [PATCH] force old selection state after creating entities Fixes vector-im/vector-web#2180 --- src/RichText.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/RichText.js b/src/RichText.js index 35ad926b91..5fe920fe50 100644 --- a/src/RichText.js +++ b/src/RichText.js @@ -273,11 +273,15 @@ export function attachImmutableEntitiesToEmoji(editorState: EditorState): Editor }); if (!newContentState.equals(contentState)) { - return EditorState.push( + const oldSelection = editorState.getSelection(); + editorState = EditorState.push( editorState, newContentState, 'convert-to-immutable-emojis', ); + // this is somewhat of a hack, we're undoing selection changes caused above + // it would be better not to make those changes in the first place + editorState = EditorState.forceSelection(editorState, oldSelection); } return editorState;