Skip to content

Commit

Permalink
Allow link-previews to trigger without needing a space
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Svenningsen <chris@carbonfive.com>
  • Loading branch information
2 people authored and josh-signal committed Nov 23, 2020
1 parent f2de142 commit f5574cb
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions ts/components/CompositionInput.tsx
Expand Up @@ -377,14 +377,23 @@ export const CompositionInput: React.ComponentType<Props> = props => {
return;
}

if (propsRef.current.onEditorStateChange) {
const selection = quill.getSelection();

propsRef.current.onEditorStateChange(
text,
mentions,
selection ? selection.index : undefined
);
const { onEditorStateChange } = propsRef.current;

if (onEditorStateChange) {
// `getSelection` inside the `onChange` event handler will be the
// selection value _before_ the change occurs. `setTimeout` 0 here will
// 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);
}
}

Expand Down

0 comments on commit f5574cb

Please sign in to comment.