From eec0fce62a921f3de940508368881511daf2068b Mon Sep 17 00:00:00 2001 From: Ken Powers Date: Thu, 22 Aug 2019 16:42:03 -0400 Subject: [PATCH] Fix composition area link previews with multiline text --- ts/components/CompositionInput.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ts/components/CompositionInput.tsx b/ts/components/CompositionInput.tsx index 10c06ebf5..f75dbd3b3 100644 --- a/ts/components/CompositionInput.tsx +++ b/ts/components/CompositionInput.tsx @@ -205,23 +205,23 @@ export const CompositionInput = ({ const updateExternalStateListeners = React.useCallback( (newState: EditorState) => { const plainText = newState.getCurrentContent().getPlainText(); - const currentBlockKey = newState.getSelection().getStartKey(); - const currentBlockIndex = editorStateRef.current + const cursorBlockKey = newState.getSelection().getStartKey(); + const cursorBlockIndex = editorStateRef.current .getCurrentContent() .getBlockMap() .keySeq() - .findIndex(key => key === currentBlockKey); + .findIndex(key => key === cursorBlockKey); const caretLocation = newState .getCurrentContent() .getBlockMap() .valueSeq() .toArray() - .reduce((sum: number, block: ContentBlock, index: number) => { - if (currentBlockIndex < index) { + .reduce((sum: number, block: ContentBlock, currentIndex: number) => { + if (currentIndex < cursorBlockIndex) { return sum + block.getText().length + 1; // +1 for newline } - if (currentBlockIndex === index) { + if (currentIndex === cursorBlockIndex) { return sum + newState.getSelection().getStartOffset(); } @@ -235,6 +235,7 @@ export const CompositionInput = ({ onDirtyChange(isDirty); } } + if (onEditorStateChange) { onEditorStateChange(plainText, caretLocation); }