Fix composition area link previews with multiline text
This commit is contained in:
parent
6cd3165c1b
commit
eec0fce62a
1 changed files with 7 additions and 6 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue