Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Fix GhTokenInput not handling keyboard shortcut bug. #1707

Merged
merged 1 commit into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/components/gh-token-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ class GhTokenInput extends Component {
}
}

// https://github.com/TryGhost/Ghost/issues/11786
// ember-power-select stops propagation of events when ctrl/CMD or meta key is down.
// So, we're dispatching KeyboardEvent directly to the root of ghost app.
if (event.ctrlKey || event.metaKey) {
const copy = new KeyboardEvent(event.type, event);
document.getElementsByClassName('gh-app')[0].dispatchEvent(copy);
event.preventDefault(); // don't show the save dialog.

return false;
}

// fallback to default
return true;
}
Expand Down
23 changes: 23 additions & 0 deletions tests/acceptance/editor-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Mirage from 'ember-cli-mirage';
import ctrlOrCmd from 'ghost-admin/utils/ctrl-or-cmd';
import moment from 'moment';
import sinon from 'sinon';
import {authenticateSession, invalidateSession} from 'ember-simple-auth/test-support';
Expand Down Expand Up @@ -829,5 +830,27 @@ describe('Acceptance: Editor', function () {
'facebook title not present after closing subview'
).to.equal(0);
});

// https://github.com/TryGhost/Ghost/issues/11786
it('save shortcut works when tags/authors field is focused', async function () {
let post = this.server.create('post', {authors: [author]});

await visit(`/editor/post/${post.id}`);
await fillIn('[data-test-editor-title-input]', 'CMD-S Test');

await click('[data-test-psm-trigger]');
await click('[data-test-token-input]');

await triggerEvent('[data-test-token-input]', 'keydown', {
keyCode: 83, // s
metaKey: ctrlOrCmd === 'command',
ctrlKey: ctrlOrCmd === 'ctrl'
});

// Check if save request has been sent correctly.
let [lastRequest] = this.server.pretender.handledRequests.slice(-1);
let body = JSON.parse(lastRequest.requestBody);
expect(body.posts[0].title).to.equal('CMD-S Test');
});
});
});