Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Issue #12859 Keyboard modifiers support for simulateKeyEvent #12863

Merged
merged 11 commits into from
Dec 23, 2016

Conversation

haslam22
Copy link
Contributor

Added support for sending additional arguments to simulateKeyEvent, e.g. modifiers such as ctrlKey: true or any other value supported by KeyboardEventInit.

@petetnt petetnt self-assigned this Nov 1, 2016
@petetnt
Copy link
Collaborator

petetnt commented Nov 25, 2016

Sorry about being so slow with this, been swamped with work as of late. I'll review this on Sunday / Monday.

Again, apologies for taking so long!

@haslam22
Copy link
Contributor Author

haslam22 commented Nov 25, 2016 via email

Copy link
Collaborator

@petetnt petetnt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some review comments, mostly looks good to me! Needs an unit test though 👍

function simulateKeyEvent(key, event, element, options) {
var doc = element.ownerDocument;

if(typeof options === 'undefined') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use Object.assign to make this a bit easier:

var defaultOptions = {
  options.view = doc.defaultView;
  options.bubbles = true;
  options.cancelable = true;
  options.keyIdentifier = key;
};
var newOptions = Object.assign({}, options, defaultOptions});
var oEvent = new KeyboardEvent(event, newOptions);


if (event !== "keydown" && event !== "keyup" && event !== "keypress") {
console.log("SpecRunnerUtils.simulateKeyEvent() - unsupported keyevent: " + event);
return;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: trailing whitespace

@haslam22
Copy link
Contributor Author

haslam22 commented Dec 1, 2016

Made the requested changes, and provided a unit test. Had to pop it in a new file, SpecRunnerUtils-test, hope that's fine. Let me know if anything else needs to be changed, thanks!

cancelable: true,
keyIdentifier: key
};
var newOptions = Object.assign({}, options, defaultOptions);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was brought up in another PR that using Object.assign actually brokes the Linux version due to using an age old CEF which doesn't support it 😢

If you could change this to the previous format then this one is ready to be merged

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem at all, reverted to the old version. 👍

@petetnt
Copy link
Collaborator

petetnt commented Dec 22, 2016

I'll try and test this out for the final time today and then merge it in, LGTM so far 🥇

@haslam22
Copy link
Contributor Author

haslam22 commented Dec 22, 2016 via email

@@ -995,15 +995,28 @@ define(function (require, exports, module) {
* Simulate key event. Found this code here:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove these comments now as the implementation is different

@petetnt
Copy link
Collaborator

petetnt commented Dec 23, 2016

Okay, one more nitpick and then it's ready to go 👍 Great work @haslam22!

@haslam22
Copy link
Contributor Author

Woops, forgot to update that part. Should be all good now.

@petetnt petetnt merged commit 7732d93 into adobe:master Dec 23, 2016
@petetnt
Copy link
Collaborator

petetnt commented Dec 23, 2016

Thanks for this great contribution @haslam22!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants