From 61e29d91bf0d176ea9fdf91eb41a1d770ff74f7e Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Wed, 21 Aug 2024 22:07:23 -0400 Subject: [PATCH] fix: Enable the 'e' shortcut to focus editor --- app/editor/index.tsx | 8 ++++++++ app/scenes/Document/components/Document.tsx | 16 +++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) 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(); } };