Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
logging-scratch-gui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Goessmann
logging-scratch-gui
Commits
def5cdc4
Commit
def5cdc4
authored
5 years ago
by
Paul Kaplan
Browse files
Options
Downloads
Patches
Plain Diff
Send keyCode if the key information is gone
parent
5c1b806f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/lib/vm-listener-hoc.jsx
+4
-4
4 additions, 4 deletions
src/lib/vm-listener-hoc.jsx
test/unit/util/vm-listener-hoc.test.jsx
+45
-0
45 additions, 0 deletions
test/unit/util/vm-listener-hoc.test.jsx
with
49 additions
and
4 deletions
src/lib/vm-listener-hoc.jsx
+
4
−
4
View file @
def5cdc4
...
...
@@ -87,9 +87,9 @@ const vmListenerHOC = function (WrappedComponent) {
// Don't capture keys intended for Blockly inputs.
if
(
e
.
target
!==
document
&&
e
.
target
!==
document
.
body
)
return
;
const
key
=
(
!
e
.
key
||
e
.
key
===
'
Dead
'
)
?
e
.
keyCode
:
e
.
key
;
this
.
props
.
vm
.
postIOData
(
'
keyboard
'
,
{
keyCode
:
e
.
keyCode
,
key
:
e
.
key
,
key
:
key
,
isDown
:
true
});
...
...
@@ -102,9 +102,9 @@ const vmListenerHOC = function (WrappedComponent) {
handleKeyUp
(
e
)
{
// Always capture up events,
// even those that have switched to other targets.
const
key
=
(
!
e
.
key
||
e
.
key
===
'
Dead
'
)
?
e
.
keyCode
:
e
.
key
;
this
.
props
.
vm
.
postIOData
(
'
keyboard
'
,
{
keyCode
:
e
.
keyCode
,
key
:
e
.
key
,
key
:
key
,
isDown
:
false
});
...
...
This diff is collapsed.
Click to expand it.
test/unit/util/vm-listener-hoc.test.jsx
+
45
−
0
View file @
def5cdc4
...
...
@@ -133,4 +133,49 @@ describe('VMListenerHOC', () => {
const
actions
=
store
.
getActions
();
expect
(
actions
.
length
).
toEqual
(
0
);
});
test
(
'
keypresses go to the vm
'
,
()
=>
{
const
Component
=
()
=>
(<
div
/>);
const
WrappedComponent
=
vmListenerHOC
(
Component
);
// Mock document.addEventListener so we can trigger keypresses manually
// Cannot use the enzyme simulate method because that only works on synthetic events
const
eventTriggers
=
{};
document
.
addEventListener
=
jest
.
fn
((
event
,
cb
)
=>
{
eventTriggers
[
event
]
=
cb
;
});
vm
.
postIOData
=
jest
.
fn
();
store
=
mockStore
({
scratchGui
:
{
mode
:
{
isFullScreen
:
true
},
modals
:
{
soundRecorder
:
true
},
vm
:
vm
}
});
mount
(
<
WrappedComponent
attachKeyboardEvents
store
=
{
store
}
vm
=
{
vm
}
/>
);
// keyboard events that do not target the document or body are ignored
eventTriggers
.
keydown
({
key
:
'
A
'
,
target
:
null
});
expect
(
vm
.
postIOData
).
not
.
toHaveBeenLastCalledWith
(
'
keyboard
'
,
{
key
:
'
A
'
,
isDown
:
true
});
// keydown/up with target as the document are sent to the vm via postIOData
eventTriggers
.
keydown
({
key
:
'
A
'
,
target
:
document
});
expect
(
vm
.
postIOData
).
toHaveBeenLastCalledWith
(
'
keyboard
'
,
{
key
:
'
A
'
,
isDown
:
true
});
eventTriggers
.
keyup
({
key
:
'
A
'
,
target
:
document
});
expect
(
vm
.
postIOData
).
toHaveBeenLastCalledWith
(
'
keyboard
'
,
{
key
:
'
A
'
,
isDown
:
false
});
// When key is 'Dead' e.g. bluetooth keyboards on iOS, it sends keyCode instead
// because the VM can process both named keys or keyCodes as the `key` property
eventTriggers
.
keyup
({
key
:
'
Dead
'
,
keyCode
:
10
,
target
:
document
});
expect
(
vm
.
postIOData
).
toHaveBeenLastCalledWith
(
'
keyboard
'
,
{
key
:
10
,
isDown
:
false
});
});
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment