diff --git a/src/component/handlers/edit/editOnBeforeInput.js b/src/component/handlers/edit/editOnBeforeInput.js index 02127db..b8cd66b 100644 --- a/src/component/handlers/edit/editOnBeforeInput.js +++ b/src/component/handlers/edit/editOnBeforeInput.js @@ -111,21 +111,42 @@ function editOnBeforeInput( // reduces re-renders and preserves spellcheck highlighting. If the selection // is not collapsed, we will re-render. var selection = editorState.getSelection(); + var selectionStart = selection.getStartOffset(); + var selectionEnd = selection.getEndOffset(); var anchorKey = selection.getAnchorKey(); if (!selection.isCollapsed()) { e.preventDefault(); - editor.update( - replaceText( - editorState, - chars, - editorState.getCurrentInlineStyle(), - getEntityKeyForSelection( - editorState.getCurrentContent(), - editorState.getSelection(), + + // If the character that the user is trying to replace with + // is the same as the current selection text the just update the + // `SelectionState`. Else, update the ContentState with the new text + var currentlySelectedChars = editorState + .getCurrentContent() + .getPlainText() + .slice(selectionStart, selectionEnd); + if (chars === currentlySelectedChars) { + this.update( + EditorState.forceSelection( + editorState, + selection.merge({ + focusOffset: selectionEnd, + }), ), - ), - ); + ); + } else { + editor.update( + replaceText( + editorState, + chars, + editorState.getCurrentInlineStyle(), + getEntityKeyForSelection( + editorState.getCurrentContent(), + editorState.getSelection(), + ), + ), + ); + } return; }