Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lexical-playground): link editor flashs #4013

Merged
merged 1 commit into from
Mar 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,29 @@ function FloatingLinkEditor({
return true;
}, [anchorElem, editor]);

useEffect(() => {
function mouseMoveListener(e: MouseEvent) {
if (editorRef?.current && (e.buttons === 1 || e.buttons === 3)) {
editorRef.current.style.pointerEvents = 'none';
}
}
function mouseUpListener(e: MouseEvent) {
if (editorRef?.current) {
editorRef.current.style.pointerEvents = 'auto';
}
}

if (editorRef?.current) {
thegreatercurve marked this conversation as resolved.
Show resolved Hide resolved
document.addEventListener('mousemove', mouseMoveListener);
document.addEventListener('mouseup', mouseUpListener);

return () => {
document.removeEventListener('mousemove', mouseMoveListener);
document.removeEventListener('mouseup', mouseUpListener);
};
}
}, [editorRef]);

useEffect(() => {
const scrollerElem = anchorElem.parentElement;

Expand Down Expand Up @@ -175,7 +198,7 @@ function FloatingLinkEditor({

return (
<div ref={editorRef} className="link-editor">
{isEditMode ? (
{!isLink ? null : isEditMode ? (
<input
ref={inputRef}
className="link-input"
Expand Down Expand Up @@ -263,17 +286,15 @@ function useFloatingLinkEditorToolbar(
);
}, [editor, updateToolbar]);

return isLink
? createPortal(
<FloatingLinkEditor
editor={activeEditor}
isLink={isLink}
anchorElem={anchorElem}
setIsLink={setIsLink}
/>,
anchorElem,
)
: null;
return createPortal(
<FloatingLinkEditor
editor={activeEditor}
isLink={isLink}
anchorElem={anchorElem}
setIsLink={setIsLink}
/>,
anchorElem,
);
}

export default function FloatingLinkEditorPlugin({
Expand Down