fix: Enter in document title should create a newline at the top of editor and focus

closes #1511
This commit is contained in:
Tom Moor
2020-09-04 13:23:27 -07:00
parent cf1e506009
commit 11d3a5c9b9

View File

@@ -40,12 +40,22 @@ class DocumentEditor extends React.Component<Props> {
}
};
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();
}