fix: Enable the 'e' shortcut to focus editor

This commit is contained in:
Tom Moor
2024-08-21 22:07:23 -04:00
parent 5e0c773826
commit 61e29d91bf
2 changed files with 17 additions and 7 deletions

View File

@@ -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.
*/

View File

@@ -242,14 +242,16 @@ class DocumentScene extends React.Component<Props> {
};
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();
}
};