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

Commit 68f3611

Browse files
committed
Fix mistake
1 parent eb9ca46 commit 68f3611

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

scripts/module-map.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
module.exports = Object.assign(
99
{
1010
immutable: 'immutable',
11-
React: 'react',
11+
react: 'react',
1212
ReactDOM: 'react-dom',
1313
ReactDOMComet: 'react-dom',
1414
'object-assign': 'object-assign',

src/component/handlers/composition/DraftEditorCompositionHandler.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,23 @@ const DraftEditorCompositionHandler = {
191191
offsetKey,
192192
);
193193

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

198199
const selection = editorState.getSelection();
199200
const selectionStart = selection.getStartOffset();
200201
const selectionEnd = selection.getEndOffset();
202+
const selectionLength = selectionEnd - selectionStart;
201203

202-
composedChars = composedChars.slice(selectionStart - start);
204+
const insertedCharsLength =
205+
composedChars.length - sourceBlockLength + selectionLength;
206+
const insertedCharsStartPos = selectionStart - startBlockPos;
207+
const insertedChars = composedChars.slice(
208+
insertedCharsStartPos,
209+
insertedCharsStartPos + insertedCharsLength,
210+
);
203211

204212
const replacementRange = editorState.getSelection().merge({
205213
anchorKey: blockKey,
@@ -215,12 +223,12 @@ const DraftEditorCompositionHandler = {
215223
);
216224
const currentStyle = contentState
217225
.getBlockForKey(blockKey)
218-
.getInlineStyleAt(start);
226+
.getInlineStyleAt(startBlockPos);
219227

220228
contentState = DraftModifier.replaceText(
221229
contentState,
222230
replacementRange,
223-
composedChars,
231+
insertedChars,
224232
currentStyle,
225233
entityKey,
226234
);

0 commit comments

Comments
 (0)