From 11d3a5c9b9c06acc722fd4a06d2b075a263395ae Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Fri, 4 Sep 2020 13:23:27 -0700 Subject: [PATCH] fix: Enter in document title should create a newline at the top of editor and focus closes #1511 --- app/scenes/Document/components/Editor.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/app/scenes/Document/components/Editor.js b/app/scenes/Document/components/Editor.js index 800ff95bb..893c1ea19 100644 --- a/app/scenes/Document/components/Editor.js +++ b/app/scenes/Document/components/Editor.js @@ -40,12 +40,22 @@ class DocumentEditor extends React.Component { } }; + insertParagraph = () => { + if (this.props.innerRef.current) { + const { view } = this.props.innerRef.current; + const { dispatch, state } = view; + dispatch(state.tr.insert(0, state.schema.nodes.paragraph.create())); + } + }; + handleTitleKeyDown = (event: SyntheticKeyboardEvent<>) => { - if ( - event.key === "Enter" || - event.key === "Tab" || - event.key === "ArrowDown" - ) { + if (event.key === "Enter") { + event.preventDefault(); + this.insertParagraph(); + this.focusAtStart(); + return; + } + if (event.key === "Tab" || event.key === "ArrowDown") { event.preventDefault(); this.focusAtStart(); }