mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-18 02:21:47 -05:00
🐛 Fixed ctrl/cmd+s not saving focused fields on general/staff settings screens
no issue - swapped from route actions triggered by shortcuts mixin to explicit `{{on-key}}` actions - when saved via keyboard, blur any focused element to trigger it's on-blur action and schedule the save to run after those actions
This commit is contained in:
parent
c77c150745
commit
e0430b4efc
8 changed files with 39 additions and 28 deletions
|
@ -9,6 +9,7 @@ import {
|
|||
IMAGE_MIME_TYPES
|
||||
} from 'ghost-admin/components/gh-image-uploader';
|
||||
import {TrackedObject} from 'tracked-built-ins';
|
||||
import {run} from '@ember/runloop';
|
||||
import {task} from 'ember-concurrency';
|
||||
import {tracked} from '@glimmer/tracking';
|
||||
|
||||
|
@ -151,4 +152,19 @@ export default class GeneralController extends Controller {
|
|||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
saveViaKeyboard(event) {
|
||||
event.preventDefault();
|
||||
|
||||
// trigger any set-on-blur actions
|
||||
const focusedElement = document.activeElement;
|
||||
focusedElement?.blur();
|
||||
|
||||
// schedule save for when set-on-blur actions have finished
|
||||
run.schedule('actions', this, function () {
|
||||
focusedElement?.focus();
|
||||
this.saveTask.perform();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -299,6 +299,20 @@ export default Controller.extend({
|
|||
}
|
||||
}).group('saveHandlers'),
|
||||
|
||||
saveViaKeyboard: action(function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
// trigger any set-on-blur actions
|
||||
const focusedElement = document.activeElement;
|
||||
focusedElement?.blur();
|
||||
|
||||
// schedule save for when set-on-blur actions have finished
|
||||
run.schedule('actions', this, function () {
|
||||
focusedElement?.focus();
|
||||
this.save.perform();
|
||||
});
|
||||
}),
|
||||
|
||||
copyContentKey: task(function* () {
|
||||
copyTextToClipboard(this.personalToken);
|
||||
yield timeout(this.isTesting ? 50 : 3000);
|
||||
|
|
|
@ -65,11 +65,6 @@ export default class GeneralSettingsRoute extends AdminRoute {
|
|||
return true;
|
||||
}
|
||||
|
||||
@action
|
||||
save() {
|
||||
return this.controller.send('save');
|
||||
}
|
||||
|
||||
@action
|
||||
reloadSettings() {
|
||||
return this.settings.reload();
|
||||
|
|
|
@ -88,11 +88,6 @@ export default class UserRoute extends AuthenticatedRoute {
|
|||
this.modelFor('settings.staff.user').get('errors').clear();
|
||||
}
|
||||
|
||||
@action
|
||||
save() {
|
||||
this.controller.save.perform();
|
||||
}
|
||||
|
||||
buildRouteInfoMetadata() {
|
||||
return {
|
||||
titleToken: 'Staff - User'
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<section class="gh-canvas">
|
||||
<section class="gh-canvas" {{on-key "cmd+s" this.saveViaKeyboard}}>
|
||||
<GhCanvasHeader class="gh-canvas-header">
|
||||
<div class="flex flex-column">
|
||||
<div class="gh-canvas-breadcrumb">
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<section class="gh-canvas">
|
||||
<section class="gh-canvas" {{on-key "cmd+s" this.saveViaKeyboard}}>
|
||||
<GhCanvasHeader class="gh-canvas-header">
|
||||
{{!-- Remove breadcrumbs for Authors and Contributors --}}
|
||||
{{#if this.currentUser.isAuthorOrContributor}}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import ctrlOrCmd from 'ghost-admin/utils/ctrl-or-cmd';
|
||||
import {authenticateSession, invalidateSession} from 'ember-simple-auth/test-support';
|
||||
import {beforeEach, describe, it} from 'mocha';
|
||||
import {blur, click, currentURL, fillIn, find, findAll, focus, triggerEvent} from '@ember/test-helpers';
|
||||
import {expect} from 'chai';
|
||||
import {keyDown} from 'ember-keyboard/test-support/test-helpers';
|
||||
import {setupApplicationTest} from 'ember-mocha';
|
||||
import {setupMirage} from 'ember-cli-mirage/test-support';
|
||||
import {visit} from '../../helpers/visit';
|
||||
|
@ -82,11 +82,7 @@ describe('Acceptance: Settings - General', function () {
|
|||
// CMD-S shortcut works
|
||||
// -------------------------------------------------------------- //
|
||||
await fillIn('[data-test-title-input]', 'CMD-S Test');
|
||||
await triggerEvent('.gh-app', 'keydown', {
|
||||
keyCode: 83, // s
|
||||
metaKey: ctrlOrCmd === 'command',
|
||||
ctrlKey: ctrlOrCmd === 'ctrl'
|
||||
});
|
||||
await keyDown('cmd+s');
|
||||
// we've already saved in this test so there's no on-screen indication
|
||||
// that we've had another save, check the request was fired instead
|
||||
let [lastRequest] = this.server.pretender.handledRequests.slice(-1);
|
||||
|
|
|
@ -1,13 +1,8 @@
|
|||
import ctrlOrCmd from 'ghost-admin/utils/ctrl-or-cmd';
|
||||
import moment from 'moment-timezone';
|
||||
import windowProxy from 'ghost-admin/utils/window-proxy';
|
||||
import {Response} from 'miragejs';
|
||||
import {afterEach, beforeEach, describe, it} from 'mocha';
|
||||
import {authenticateSession, invalidateSession} from 'ember-simple-auth/test-support';
|
||||
import {enableLabsFlag} from '../helpers/labs-flag';
|
||||
import {enableMembers} from '../helpers/members';
|
||||
import {enableStripe} from '../helpers/stripe';
|
||||
|
||||
import {
|
||||
blur,
|
||||
click,
|
||||
|
@ -20,7 +15,11 @@ import {
|
|||
triggerEvent,
|
||||
triggerKeyEvent
|
||||
} from '@ember/test-helpers';
|
||||
import {enableLabsFlag} from '../helpers/labs-flag';
|
||||
import {enableMembers} from '../helpers/members';
|
||||
import {enableStripe} from '../helpers/stripe';
|
||||
import {expect} from 'chai';
|
||||
import {keyDown} from 'ember-keyboard/test-support/test-helpers';
|
||||
import {setupApplicationTest} from 'ember-mocha';
|
||||
import {setupMirage} from 'ember-cli-mirage/test-support';
|
||||
import {visit} from '../helpers/visit';
|
||||
|
@ -521,11 +520,7 @@ describe('Acceptance: Staff', function () {
|
|||
|
||||
// CMD-S shortcut works
|
||||
await fillIn('[data-test-slug-input]', 'Test User');
|
||||
await triggerEvent('.gh-app', 'keydown', {
|
||||
keyCode: 83, // s
|
||||
metaKey: ctrlOrCmd === 'command',
|
||||
ctrlKey: ctrlOrCmd === 'ctrl'
|
||||
});
|
||||
await keyDown('cmd+s');
|
||||
|
||||
// Since we reset save status so there's no on-screen indication
|
||||
// that we've had a save, check the request was fired instead
|
||||
|
|
Loading…
Add table
Reference in a new issue