diff --git a/packages/web/src/javascripts/Components/SuperEditor/BlocksEditor.tsx b/packages/web/src/javascripts/Components/SuperEditor/BlocksEditor.tsx index 81b39e7d6..d44fe00dc 100644 --- a/packages/web/src/javascripts/Components/SuperEditor/BlocksEditor.tsx +++ b/packages/web/src/javascripts/Components/SuperEditor/BlocksEditor.tsx @@ -78,23 +78,29 @@ export const BlocksEditor: FunctionComponent = ({ return ( <> {!isMobile && } - -
- -
+
+ +
+ +
+
-
- } - placeholder={null} - ErrorBoundary={LexicalErrorBoundary} - /> + } + placeholder={ +
+ Type / for commands... +
+ } + ErrorBoundary={LexicalErrorBoundary} + /> +
{isMobile && } diff --git a/packages/web/src/javascripts/Components/SuperEditor/Plugins/EmptyLinePlaceholderPlugin.tsx b/packages/web/src/javascripts/Components/SuperEditor/Plugins/EmptyLinePlaceholderPlugin.tsx deleted file mode 100644 index 0ed7ea433..000000000 --- a/packages/web/src/javascripts/Components/SuperEditor/Plugins/EmptyLinePlaceholderPlugin.tsx +++ /dev/null @@ -1,92 +0,0 @@ -import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext' -import { - $getSelection, - $isRangeSelection, - $isParagraphNode, - $isTextNode, - SELECTION_CHANGE_COMMAND, - COMMAND_PRIORITY_LOW, -} from 'lexical' -import { useCallback, useEffect, useRef } from 'react' -import { getSelectedNode } from '../Lexical/Utils/getSelectedNode' -import { mergeRegister } from '@lexical/utils' - -export const EmptyLinePlaceholderPlugin = () => { - const [editor] = useLexicalComposerContext() - - const placeholderElementRef = useRef(null) - - const cursorUpdate = useCallback((): boolean => { - const selection = $getSelection() - if (selection && $isRangeSelection(selection)) { - if (!placeholderElementRef.current) { - return false - } - const node = getSelectedNode(selection) - if (!node) { - return false - } - const isParagraph = $isParagraphNode(node) || $isTextNode(node) - const text = node.getTextContent() - if (!isParagraph) { - return false - } - const rootElement = editor.getRootElement() - const nodeElement = editor.getElementByKey(node.getKey()) - const placeholder = placeholderElementRef.current - if (!nodeElement || !placeholder.parentElement || !rootElement) { - return false - } - const rect = nodeElement.getBoundingClientRect() - const parentRect = placeholder.parentElement.getBoundingClientRect() - const rootRect = rootElement.getBoundingClientRect() - if (!text && editor.isEditable()) { - placeholder.style.top = `${rect.y}px` - placeholder.style.left = `${rect.x - parentRect.x + rootRect.x}px` - placeholder.style.opacity = '0.65' - } else { - placeholder.style.opacity = '0' - } - } - - return false - }, [editor]) - - useEffect(() => { - return mergeRegister( - editor.registerCommand(SELECTION_CHANGE_COMMAND, cursorUpdate, COMMAND_PRIORITY_LOW), - editor.registerEditableListener(cursorUpdate), - ) - }, [cursorUpdate, editor]) - - useEffect(() => { - const scrollerElem = editor.getRootElement() - - const update = () => { - editor.getEditorState().read(() => { - cursorUpdate() - }) - } - - window.addEventListener('resize', update) - if (scrollerElem) { - scrollerElem.addEventListener('scroll', update) - } - - return () => { - window.removeEventListener('resize', update) - if (scrollerElem) { - scrollerElem.removeEventListener('scroll', update) - } - } - }, [cursorUpdate, editor]) - - return ( -
- Type / for commands... -
- ) -}