diff --git a/app/editor/index.tsx b/app/editor/index.tsx index d1210e5bd1..c077df765e 100644 --- a/app/editor/index.tsx +++ b/app/editor/index.tsx @@ -561,6 +561,14 @@ export class Editor extends React.PureComponent< this.view.focus(); }; + /** + * Focus the editor and scroll to the current selection. + */ + public focus = () => { + this.view.focus(); + this.view.dispatch(this.view.state.tr.scrollIntoView()); + }; + /** * Blur the editor. */ diff --git a/app/scenes/Document/components/Document.tsx b/app/scenes/Document/components/Document.tsx index 3f2cafcfa2..752915e895 100644 --- a/app/scenes/Document/components/Document.tsx +++ b/app/scenes/Document/components/Document.tsx @@ -242,14 +242,16 @@ class DocumentScene extends React.Component { }; goToEdit = (ev: KeyboardEvent) => { - if (!this.props.readOnly) { - return; - } - ev.preventDefault(); - const { document, abilities } = this.props; + if (this.props.readOnly) { + ev.preventDefault(); + const { document, abilities } = this.props; - if (abilities.update) { - this.props.history.push(documentEditPath(document)); + if (abilities.update) { + this.props.history.push(documentEditPath(document)); + } + } else if (this.editor.current?.isBlurred) { + ev.preventDefault(); + this.editor.current?.focus(); } };