Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Attempt to fix same charcter selection and replacing bug. #719

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions src/component/handlers/edit/editOnBeforeInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down