feat: Add keyboard shortcut to publish document

closes #1073
This commit is contained in:
Tom Moor
2019-10-27 18:04:35 -07:00
parent 98cd93c99c
commit 9ef9c75c6b
3 changed files with 33 additions and 7 deletions

View File

@ -155,6 +155,14 @@ class DocumentScene extends React.Component<Props> {
}
}
@keydown('meta+shift+p')
onPublish(ev) {
ev.preventDefault();
if (!this.document) return;
if (this.document.publishedAt) return;
this.onSave({ publish: true, done: true });
}
loadDocument = async props => {
const { shareId, revisionId } = props.match.params;
@ -409,6 +417,7 @@ class DocumentScene extends React.Component<Props> {
onSearchLink={this.onSearchLink}
onChange={this.onChange}
onSave={this.onSave}
onPublish={this.onPublish}
onCancel={this.onDiscard}
readOnly={!this.isEditing || document.isArchived}
toc={!revision}

View File

@ -189,6 +189,12 @@ class Header extends React.Component<Props> {
{can.update &&
isDraft && (
<Action>
<Tooltip
tooltip="Publish"
shortcut={`${meta}+shift+p`}
delay={500}
placement="bottom"
>
<Button
onClick={this.handlePublish}
title="Publish document"
@ -197,6 +203,7 @@ class Header extends React.Component<Props> {
>
{isPublishing ? 'Publishing…' : 'Publish'}
</Button>
</Tooltip>
</Action>
)}
{canEdit && (

View File

@ -1,6 +1,7 @@
// @flow
import { Node, Editor } from 'slate';
import Placeholder from 'rich-markdown-editor/lib/plugins/Placeholder';
import isModKey from 'rich-markdown-editor/lib/lib/isModKey';
export default [
Placeholder({
@ -25,4 +26,13 @@ export default [
return true;
},
}),
{
onKeyDown(ev: SyntheticKeyboardEvent<>, editor: Editor, next: Function) {
if (ev.key === 'p' && ev.shiftKey && isModKey(ev)) {
return editor.props.onPublish(ev);
}
return next();
},
},
];