Reflect API change for creating an Entity
This commit is contained in:
parent
4f0cf7d6ec
commit
124795006c
2 changed files with 9 additions and 11 deletions
|
@ -248,7 +248,10 @@ export function attachImmutableEntitiesToEmoji(editorState: EditorState): Editor
|
||||||
.set('anchorOffset', start)
|
.set('anchorOffset', start)
|
||||||
.set('focusOffset', end);
|
.set('focusOffset', end);
|
||||||
const emojiText = plainText.substring(start, end);
|
const emojiText = plainText.substring(start, end);
|
||||||
const entityKey = Entity.create('emoji', 'IMMUTABLE', { emojiUnicode: emojiText });
|
newContentState = newContentState.createEntity(
|
||||||
|
'emoji', 'IMMUTABLE', { emojiUnicode: emojiText }
|
||||||
|
);
|
||||||
|
const entityKey = newContentState.getLastCreatedEntityKey();
|
||||||
newContentState = Modifier.replaceText(
|
newContentState = Modifier.replaceText(
|
||||||
newContentState,
|
newContentState,
|
||||||
selection,
|
selection,
|
||||||
|
|
|
@ -936,32 +936,27 @@ export default class MessageComposerInput extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
const {range = null, completion = '', href = null, suffix = ''} = displayedCompletion;
|
const {range = null, completion = '', href = null, suffix = ''} = displayedCompletion;
|
||||||
|
let contentState = activeEditorState.getCurrentContent();
|
||||||
|
|
||||||
let entityKey;
|
let entityKey;
|
||||||
let mdCompletion;
|
|
||||||
if (href) {
|
if (href) {
|
||||||
entityKey = Entity.create('LINK', 'IMMUTABLE', {
|
contentState = contentState.createEntity('LINK', 'IMMUTABLE', {
|
||||||
url: href,
|
url: href,
|
||||||
isCompletion: true,
|
isCompletion: true,
|
||||||
});
|
});
|
||||||
|
entityKey = contentState.getLastCreatedEntityKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
let selection;
|
let selection;
|
||||||
if (range) {
|
if (range) {
|
||||||
selection = RichText.textOffsetsToSelectionState(
|
selection = RichText.textOffsetsToSelectionState(
|
||||||
range, activeEditorState.getCurrentContent().getBlocksAsArray(),
|
range, contentState.getBlocksAsArray(),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
selection = activeEditorState.getSelection();
|
selection = activeEditorState.getSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
let contentState = Modifier.replaceText(
|
contentState = Modifier.replaceText(contentState, selection, completion, null, entityKey);
|
||||||
activeEditorState.getCurrentContent(),
|
|
||||||
selection,
|
|
||||||
mdCompletion || completion,
|
|
||||||
null,
|
|
||||||
entityKey,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Move the selection to the end of the block
|
// Move the selection to the end of the block
|
||||||
const afterSelection = contentState.getSelectionAfter();
|
const afterSelection = contentState.getSelectionAfter();
|
||||||
|
|
Loading…
Reference in a new issue