mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-25 02:31:59 -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
|
IMAGE_MIME_TYPES
|
||||||
} from 'ghost-admin/components/gh-image-uploader';
|
} from 'ghost-admin/components/gh-image-uploader';
|
||||||
import {TrackedObject} from 'tracked-built-ins';
|
import {TrackedObject} from 'tracked-built-ins';
|
||||||
|
import {run} from '@ember/runloop';
|
||||||
import {task} from 'ember-concurrency';
|
import {task} from 'ember-concurrency';
|
||||||
import {tracked} from '@glimmer/tracking';
|
import {tracked} from '@glimmer/tracking';
|
||||||
|
|
||||||
|
@ -151,4 +152,19 @@ export default class GeneralController extends Controller {
|
||||||
throw error;
|
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'),
|
}).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* () {
|
copyContentKey: task(function* () {
|
||||||
copyTextToClipboard(this.personalToken);
|
copyTextToClipboard(this.personalToken);
|
||||||
yield timeout(this.isTesting ? 50 : 3000);
|
yield timeout(this.isTesting ? 50 : 3000);
|
||||||
|
|
|
@ -65,11 +65,6 @@ export default class GeneralSettingsRoute extends AdminRoute {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
|
||||||
save() {
|
|
||||||
return this.controller.send('save');
|
|
||||||
}
|
|
||||||
|
|
||||||
@action
|
@action
|
||||||
reloadSettings() {
|
reloadSettings() {
|
||||||
return this.settings.reload();
|
return this.settings.reload();
|
||||||
|
|
|
@ -88,11 +88,6 @@ export default class UserRoute extends AuthenticatedRoute {
|
||||||
this.modelFor('settings.staff.user').get('errors').clear();
|
this.modelFor('settings.staff.user').get('errors').clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
|
||||||
save() {
|
|
||||||
this.controller.save.perform();
|
|
||||||
}
|
|
||||||
|
|
||||||
buildRouteInfoMetadata() {
|
buildRouteInfoMetadata() {
|
||||||
return {
|
return {
|
||||||
titleToken: 'Staff - User'
|
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">
|
<GhCanvasHeader class="gh-canvas-header">
|
||||||
<div class="flex flex-column">
|
<div class="flex flex-column">
|
||||||
<div class="gh-canvas-breadcrumb">
|
<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">
|
<GhCanvasHeader class="gh-canvas-header">
|
||||||
{{!-- Remove breadcrumbs for Authors and Contributors --}}
|
{{!-- Remove breadcrumbs for Authors and Contributors --}}
|
||||||
{{#if this.currentUser.isAuthorOrContributor}}
|
{{#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 {authenticateSession, invalidateSession} from 'ember-simple-auth/test-support';
|
||||||
import {beforeEach, describe, it} from 'mocha';
|
import {beforeEach, describe, it} from 'mocha';
|
||||||
import {blur, click, currentURL, fillIn, find, findAll, focus, triggerEvent} from '@ember/test-helpers';
|
import {blur, click, currentURL, fillIn, find, findAll, focus, triggerEvent} from '@ember/test-helpers';
|
||||||
import {expect} from 'chai';
|
import {expect} from 'chai';
|
||||||
|
import {keyDown} from 'ember-keyboard/test-support/test-helpers';
|
||||||
import {setupApplicationTest} from 'ember-mocha';
|
import {setupApplicationTest} from 'ember-mocha';
|
||||||
import {setupMirage} from 'ember-cli-mirage/test-support';
|
import {setupMirage} from 'ember-cli-mirage/test-support';
|
||||||
import {visit} from '../../helpers/visit';
|
import {visit} from '../../helpers/visit';
|
||||||
|
@ -82,11 +82,7 @@ describe('Acceptance: Settings - General', function () {
|
||||||
// CMD-S shortcut works
|
// CMD-S shortcut works
|
||||||
// -------------------------------------------------------------- //
|
// -------------------------------------------------------------- //
|
||||||
await fillIn('[data-test-title-input]', 'CMD-S Test');
|
await fillIn('[data-test-title-input]', 'CMD-S Test');
|
||||||
await triggerEvent('.gh-app', 'keydown', {
|
await keyDown('cmd+s');
|
||||||
keyCode: 83, // s
|
|
||||||
metaKey: ctrlOrCmd === 'command',
|
|
||||||
ctrlKey: ctrlOrCmd === 'ctrl'
|
|
||||||
});
|
|
||||||
// we've already saved in this test so there's no on-screen indication
|
// 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
|
// that we've had another save, check the request was fired instead
|
||||||
let [lastRequest] = this.server.pretender.handledRequests.slice(-1);
|
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 moment from 'moment-timezone';
|
||||||
import windowProxy from 'ghost-admin/utils/window-proxy';
|
import windowProxy from 'ghost-admin/utils/window-proxy';
|
||||||
import {Response} from 'miragejs';
|
import {Response} from 'miragejs';
|
||||||
import {afterEach, beforeEach, describe, it} from 'mocha';
|
import {afterEach, beforeEach, describe, it} from 'mocha';
|
||||||
import {authenticateSession, invalidateSession} from 'ember-simple-auth/test-support';
|
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 {
|
import {
|
||||||
blur,
|
blur,
|
||||||
click,
|
click,
|
||||||
|
@ -20,7 +15,11 @@ import {
|
||||||
triggerEvent,
|
triggerEvent,
|
||||||
triggerKeyEvent
|
triggerKeyEvent
|
||||||
} from '@ember/test-helpers';
|
} 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 {expect} from 'chai';
|
||||||
|
import {keyDown} from 'ember-keyboard/test-support/test-helpers';
|
||||||
import {setupApplicationTest} from 'ember-mocha';
|
import {setupApplicationTest} from 'ember-mocha';
|
||||||
import {setupMirage} from 'ember-cli-mirage/test-support';
|
import {setupMirage} from 'ember-cli-mirage/test-support';
|
||||||
import {visit} from '../helpers/visit';
|
import {visit} from '../helpers/visit';
|
||||||
|
@ -521,11 +520,7 @@ describe('Acceptance: Staff', function () {
|
||||||
|
|
||||||
// CMD-S shortcut works
|
// CMD-S shortcut works
|
||||||
await fillIn('[data-test-slug-input]', 'Test User');
|
await fillIn('[data-test-slug-input]', 'Test User');
|
||||||
await triggerEvent('.gh-app', 'keydown', {
|
await keyDown('cmd+s');
|
||||||
keyCode: 83, // s
|
|
||||||
metaKey: ctrlOrCmd === 'command',
|
|
||||||
ctrlKey: ctrlOrCmd === 'ctrl'
|
|
||||||
});
|
|
||||||
|
|
||||||
// Since we reset save status so there's no on-screen indication
|
// Since we reset save status so there's no on-screen indication
|
||||||
// that we've had a save, check the request was fired instead
|
// that we've had a save, check the request was fired instead
|
||||||
|
|
Loading…
Add table
Reference in a new issue