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

Commit

Permalink
Fix mistake
Browse files Browse the repository at this point in the history
  • Loading branch information
offcall committed Oct 10, 2021
1 parent eb9ca46 commit 68f3611
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion scripts/module-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
module.exports = Object.assign(
{
immutable: 'immutable',
React: 'react',
react: 'react',
ReactDOM: 'react-dom',
ReactDOMComet: 'react-dom',
'object-assign': 'object-assign',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,23 @@ const DraftEditorCompositionHandler = {
offsetKey,
);

const {start} = editorState
const {start: startBlockPos, end: endBlockPos} = editorState
.getBlockTree(blockKey)
.getIn([decoratorKey, 'leaves', leafKey]);
const sourceBlockLength = endBlockPos - startBlockPos;

const selection = editorState.getSelection();
const selectionStart = selection.getStartOffset();
const selectionEnd = selection.getEndOffset();
const selectionLength = selectionEnd - selectionStart;

composedChars = composedChars.slice(selectionStart - start);
const insertedCharsLength =
composedChars.length - sourceBlockLength + selectionLength;
const insertedCharsStartPos = selectionStart - startBlockPos;
const insertedChars = composedChars.slice(
insertedCharsStartPos,
insertedCharsStartPos + insertedCharsLength,
);

const replacementRange = editorState.getSelection().merge({
anchorKey: blockKey,
Expand All @@ -215,12 +223,12 @@ const DraftEditorCompositionHandler = {
);
const currentStyle = contentState
.getBlockForKey(blockKey)
.getInlineStyleAt(start);
.getInlineStyleAt(startBlockPos);

contentState = DraftModifier.replaceText(
contentState,
replacementRange,
composedChars,
insertedChars,
currentStyle,
entityKey,
);
Expand Down

0 comments on commit 68f3611

Please sign in to comment.