Allow link-previews to trigger without needing a space
Co-authored-by: Chris Svenningsen <chris@carbonfive.com>
This commit is contained in:
parent
21c322f7fa
commit
3bc68b20ea
1 changed files with 16 additions and 7 deletions
|
@ -377,14 +377,23 @@ export const CompositionInput: React.ComponentType<Props> = props => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (propsRef.current.onEditorStateChange) {
|
const { onEditorStateChange } = propsRef.current;
|
||||||
const selection = quill.getSelection();
|
|
||||||
|
|
||||||
propsRef.current.onEditorStateChange(
|
if (onEditorStateChange) {
|
||||||
text,
|
// `getSelection` inside the `onChange` event handler will be the
|
||||||
mentions,
|
// selection value _before_ the change occurs. `setTimeout` 0 here will
|
||||||
selection ? selection.index : undefined
|
// let `getSelection` return the selection after the change takes place.
|
||||||
);
|
// this is necessary for `maybeGrabLinkPreview` as it needs the correct
|
||||||
|
// `caretLocation` from the post-change selection index value.
|
||||||
|
setTimeout(() => {
|
||||||
|
const selection = quill.getSelection();
|
||||||
|
|
||||||
|
onEditorStateChange(
|
||||||
|
text,
|
||||||
|
mentions,
|
||||||
|
selection ? selection.index : undefined
|
||||||
|
);
|
||||||
|
}, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue