From 72fe327c3bcea5e95f7be374fdc0a53fa93be819 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Wed, 11 May 2016 11:59:36 +0200 Subject: [PATCH] Fix cmd-s shortcut not saving changes in text fields with focusout closes #4556 - when CMD-S is used, if the focused element is an input, trigger it's `focusout` handler then schedule the save action to happen after any actions resulting from the trigger --- core/client/app/mixins/editor-base-route.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/core/client/app/mixins/editor-base-route.js b/core/client/app/mixins/editor-base-route.js index 66aebd11fc..01d35785d8 100644 --- a/core/client/app/mixins/editor-base-route.js +++ b/core/client/app/mixins/editor-base-route.js @@ -3,7 +3,7 @@ import ShortcutsRoute from 'ghost/mixins/shortcuts-route'; import styleBody from 'ghost/mixins/style-body'; import ctrlOrCmd from 'ghost/utils/ctrl-or-cmd'; -const {Mixin, RSVP, run} = Ember; +const {$, Mixin, RSVP, run} = Ember; let generalShortcuts = {}; generalShortcuts[`${ctrlOrCmd}+alt+p`] = 'publish'; @@ -16,7 +16,15 @@ export default Mixin.create(styleBody, ShortcutsRoute, { actions: { save() { - this.get('controller').send('save'); + let selectedElement = $(document.activeElement); + + if (selectedElement.is('input[type="text"]')) { + selectedElement.trigger('focusout'); + } + + run.scheduleOnce('actions', this, function () { + this.get('controller').send('save'); + }); }, publish() {