Moved cmd+shift+p shortcut handling into <GhPublishmenu>

refs https://github.com/TryGhost/Team/issues/1169

We want all publish actions to trigger a confirmation modal. Currently that confirmation modal is controlled by `<GhPublishmenu>` which made it difficult to use from the route-induced publish shortcut.

- removed old shortcut mixin approach from the editor route
- added modern keyboard handler to a hidden element that is rendered any time the publish menu is present
This commit is contained in:
Kevin Ansfield 2021-12-01 11:50:51 +00:00
parent 80148c64db
commit 84b8d1be3b
3 changed files with 27 additions and 9 deletions

View File

@ -79,4 +79,10 @@
@close={{this.closeEmailConfirmationModal}}
@modifier="action wide"
/>
{{/if}}
{{/if}}
{{!--
Workaround to have an always-shown element to attach key handlers to.
TODO: Move onto main element once converted to a glimmer component
--}}
<div class="hidden" {{on-key "cmd+shift+p" (action "publishFromShortcut")}}></div>

View File

@ -3,6 +3,7 @@ import EmailFailedError from 'ghost-admin/errors/email-failed-error';
import {action} from '@ember/object';
import {computed} from '@ember/object';
import {or, reads} from '@ember/object/computed';
import {schedule} from '@ember/runloop';
import {inject as service} from '@ember/service';
import {task, timeout} from 'ember-concurrency';
@ -280,6 +281,25 @@ export default Component.extend({
updateMemberCount(count) {
this.memberCount = count;
},
publishFromShortcut() {
// trigger blur for inputs and textareas to trigger any actions
// before attempting to save so we're saving after the result
if (document.activeElement?.matches('input[type="text"], textarea')) {
// trigger focusout so that it bubbles
const focusout = new Event('focusout');
document.activeElement.dispatchEvent(focusout);
// make sure blur event is triggered too
document.activeElement.blur();
}
// wait for actions to be triggered by the focusout/blur before saving
schedule('actions', this, function () {
this.send('setSaveType', 'published');
this.save.perform();
});
}
},

View File

@ -7,7 +7,6 @@ import {run} from '@ember/runloop';
import {inject as service} from '@ember/service';
let generalShortcuts = {};
generalShortcuts[`${ctrlOrCmd}+shift+p`] = 'publish';
generalShortcuts[`${ctrlOrCmd}+p`] = 'preview';
export default AuthenticatedRoute.extend(ShortcutsRoute, {
@ -48,13 +47,6 @@ export default AuthenticatedRoute.extend(ShortcutsRoute, {
});
},
publish() {
this._blurAndScheduleAction(function () {
this.controller.send('setSaveType', 'publish');
this.controller.send('save');
});
},
preview() {
if (this.controller.post.isDraft) {
this.controller.send('openPostPreviewModal');