diff --git a/webapp/src/components/markdownEditorInput/markdownEditorInput.tsx b/webapp/src/components/markdownEditorInput/markdownEditorInput.tsx index f93a2aefa..1ecc13107 100644 --- a/webapp/src/components/markdownEditorInput/markdownEditorInput.tsx +++ b/webapp/src/components/markdownEditorInput/markdownEditorInput.tsx @@ -47,12 +47,13 @@ const MarkdownEditorInput = (props: Props): ReactElement => { , [workspaceUsers]) const ref = useRef(null) - const generateEditorState = (text?: string): EditorState => { - return EditorState.createWithContent(ContentState.createFromText(text || '')) + const generateEditorState = (text?: string) => { + const state = EditorState.createWithContent(ContentState.createFromText(text || '')) + return EditorState.moveSelectionToEnd(state) } const [editorState, setEditorState] = useState(() => { - return EditorState.moveSelectionToEnd(generateEditorState(initialText)) + return generateEditorState(initialText) }) // avoiding stale closure @@ -91,7 +92,7 @@ const MarkdownEditorInput = (props: Props): ReactElement => { } setTimeout(() => ref.current?.focus(), 200) } - }, [isEditing]) + }, [isEditing, initialText]) const customKeyBindingFn = useCallback((e: React.KeyboardEvent) => { if (isMentionPopoverOpen || isEmojiPopoverOpen) {