Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
d62c7ecc
Unverified
Commit
d62c7ecc
authored
Apr 01, 2020
by
cjng96
Committed by
GitHub
Apr 01, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ignore key events on edit control on web platform (#52656) (#52661)
parent
2a649b16
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
129 additions
and
6 deletions
+129
-6
editable.dart
packages/flutter/lib/src/rendering/editable.dart
+6
-1
editable_test.dart
packages/flutter/test/rendering/editable_test.dart
+52
-0
event_simulation.dart
packages/flutter_test/lib/src/event_simulation.dart
+71
-5
No files found.
packages/flutter/lib/src/rendering/editable.dart
View file @
d62c7ecc
...
...
@@ -473,6 +473,11 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
// string using Unicode scalar values, rather than using the number of
// extended grapheme clusters (a.k.a. "characters" in the end user's mind).
void
_handleKeyEvent
(
RawKeyEvent
keyEvent
)
{
if
(
kIsWeb
)
{
// On web platform, we should ignore the key because it's processed already.
return
;
}
if
(
keyEvent
is
!
RawKeyDownEvent
||
onSelectionChanged
==
null
)
return
;
final
Set
<
LogicalKeyboardKey
>
keysPressed
=
LogicalKeyboardKey
.
collapseSynonyms
(
RawKeyboard
.
instance
.
keysPressed
);
...
...
packages/flutter/test/rendering/editable_test.dart
View file @
d62c7ecc
...
...
@@ -368,6 +368,58 @@ void main() {
expect
(
editable
,
paintsExactlyCountTimes
(
#drawRect
,
1
));
},
skip:
isBrowser
);
test
(
'ignore key event from web platform'
,
()
async
{
final
TextSelectionDelegate
delegate
=
FakeEditableTextState
();
final
ViewportOffset
viewportOffset
=
ViewportOffset
.
zero
();
TextSelection
currentSelection
;
final
RenderEditable
editable
=
RenderEditable
(
backgroundCursorColor:
Colors
.
grey
,
selectionColor:
Colors
.
black
,
textDirection:
TextDirection
.
ltr
,
cursorColor:
Colors
.
red
,
offset:
viewportOffset
,
// This makes the scroll axis vertical.
maxLines:
2
,
textSelectionDelegate:
delegate
,
onSelectionChanged:
(
TextSelection
selection
,
RenderEditable
renderObject
,
SelectionChangedCause
cause
)
{
currentSelection
=
selection
;
},
startHandleLayerLink:
LayerLink
(),
endHandleLayerLink:
LayerLink
(),
text:
const
TextSpan
(
text:
'test
\n
test'
,
style:
TextStyle
(
height:
1.0
,
fontSize:
10.0
,
fontFamily:
'Ahem'
,
),
),
selection:
const
TextSelection
.
collapsed
(
offset:
4
,
),
);
layout
(
editable
);
editable
.
hasFocus
=
true
;
expect
(
editable
,
paints
..
paragraph
(
offset:
Offset
.
zero
),
);
editable
.
selectPositionAt
(
from:
const
Offset
(
0
,
0
),
cause:
SelectionChangedCause
.
tap
);
editable
.
selection
=
const
TextSelection
.
collapsed
(
offset:
0
);
pumpFrame
();
if
(
kIsWeb
)
{
await
simulateKeyDownEvent
(
LogicalKeyboardKey
.
arrowRight
,
platform:
'web'
);
expect
(
currentSelection
.
isCollapsed
,
true
);
expect
(
currentSelection
.
baseOffset
,
0
);
}
else
{
await
simulateKeyDownEvent
(
LogicalKeyboardKey
.
arrowRight
,
platform:
'android'
);
expect
(
currentSelection
.
isCollapsed
,
true
);
expect
(
currentSelection
.
baseOffset
,
1
);
}
});
test
(
'selects correct place with offsets'
,
()
{
final
TextSelectionDelegate
delegate
=
FakeEditableTextState
();
final
ViewportOffset
viewportOffset
=
ViewportOffset
.
zero
();
...
...
packages/flutter_test/lib/src/event_simulation.dart
View file @
d62c7ecc
...
...
@@ -39,6 +39,7 @@ class KeyEventSimulator {
case
'fuchsia'
:
case
'macos'
:
case
'linux'
:
case
'web'
:
return
true
;
}
return
false
;
...
...
@@ -61,6 +62,9 @@ class KeyEventSimulator {
case
'linux'
:
map
=
kLinuxToPhysicalKey
;
break
;
case
'web'
:
// web doesn't have int type code
return
null
;
}
for
(
final
int
code
in
map
.
keys
)
{
if
(
key
.
usbHidUsage
==
map
[
code
].
usbHidUsage
)
{
...
...
@@ -85,6 +89,9 @@ class KeyEventSimulator {
case
'macos'
:
// macOS doesn't do key codes, just scan codes.
return
null
;
case
'web'
:
// web doesn't have int type code
return
null
;
case
'linux'
:
map
=
kGlfwToLogicalKey
;
break
;
...
...
@@ -97,10 +104,18 @@ class KeyEventSimulator {
}
return
keyCode
;
}
static
String
_getWebKeyCode
(
LogicalKeyboardKey
key
)
{
for
(
final
String
code
in
kWebToLogicalKey
.
keys
)
{
if
(
key
.
keyId
==
kWebToLogicalKey
[
code
].
keyId
)
{
return
code
;
}
}
return
null
;
}
static
PhysicalKeyboardKey
_findPhysicalKey
(
LogicalKeyboardKey
key
,
String
platform
)
{
assert
(
_osIsSupported
(
platform
),
'Platform
$platform
not supported for key simulation'
);
Map
<
int
,
PhysicalKeyboardKey
>
map
;
Map
<
dynamic
,
PhysicalKeyboardKey
>
map
;
switch
(
platform
)
{
case
'android'
:
map
=
kAndroidToPhysicalKey
;
...
...
@@ -114,6 +129,9 @@ class KeyEventSimulator {
case
'linux'
:
map
=
kLinuxToPhysicalKey
;
break
;
case
'web'
:
map
=
kWebToPhysicalKey
;
break
;
}
for
(
final
PhysicalKeyboardKey
physicalKey
in
map
.
values
)
{
if
(
key
.
debugName
==
physicalKey
.
debugName
)
{
...
...
@@ -138,10 +156,10 @@ class KeyEventSimulator {
physicalKey
??=
_findPhysicalKey
(
key
,
platform
);
assert
(
key
.
debugName
!=
null
);
final
int
keyCode
=
platform
==
'macos'
?
-
1
:
_getKeyCode
(
key
,
platform
);
assert
(
platform
==
'macos'
||
keyCode
!=
null
,
'Key
$key
not found in
$platform
keyCode map'
);
final
int
scanCode
=
_getScanCode
(
physicalKey
,
platform
);
assert
(
scanCode
!=
null
,
'Physical key for
$key
not found in
$platform
scanCode map'
);
final
int
keyCode
=
platform
==
'macos'
||
platform
==
'web'
?
-
1
:
_getKeyCode
(
key
,
platform
);
assert
(
platform
==
'macos'
||
platform
==
'web'
||
keyCode
!=
null
,
'Key
$key
not found in
$platform
keyCode map'
);
final
int
scanCode
=
platform
==
'web'
?
-
1
:
_getScanCode
(
physicalKey
,
platform
);
assert
(
platform
==
'web'
||
scanCode
!=
null
,
'Physical key for
$key
not found in
$platform
scanCode map'
);
final
Map
<
String
,
dynamic
>
result
=
<
String
,
dynamic
>{
'type'
:
isDown
?
'keydown'
:
'keyup'
,
...
...
@@ -173,6 +191,10 @@ class KeyEventSimulator {
result
[
'charactersIgnoringModifiers'
]
=
key
.
keyLabel
;
result
[
'modifiers'
]
=
_getMacOsModifierFlags
(
key
,
isDown
);
break
;
case
'web'
:
result
[
'code'
]
=
_getWebKeyCode
(
key
);
result
[
'key'
]
=
''
;
result
[
'metaState'
]
=
_getWebModifierFlags
(
key
,
isDown
);
}
return
result
;
}
...
...
@@ -288,6 +310,50 @@ class KeyEventSimulator {
return
result
;
}
static
int
_getWebModifierFlags
(
LogicalKeyboardKey
newKey
,
bool
isDown
)
{
int
result
=
0
;
final
Set
<
LogicalKeyboardKey
>
pressed
=
RawKeyboard
.
instance
.
keysPressed
;
if
(
isDown
)
{
pressed
.
add
(
newKey
);
}
else
{
pressed
.
remove
(
newKey
);
}
if
(
pressed
.
contains
(
LogicalKeyboardKey
.
shiftLeft
))
{
result
|=
RawKeyEventDataWeb
.
modifierShift
;
}
if
(
pressed
.
contains
(
LogicalKeyboardKey
.
shiftRight
))
{
result
|=
RawKeyEventDataWeb
.
modifierShift
;
}
if
(
pressed
.
contains
(
LogicalKeyboardKey
.
metaLeft
))
{
result
|=
RawKeyEventDataWeb
.
modifierMeta
;
}
if
(
pressed
.
contains
(
LogicalKeyboardKey
.
metaRight
))
{
result
|=
RawKeyEventDataWeb
.
modifierMeta
;
}
if
(
pressed
.
contains
(
LogicalKeyboardKey
.
controlLeft
))
{
result
|=
RawKeyEventDataWeb
.
modifierControl
;
}
if
(
pressed
.
contains
(
LogicalKeyboardKey
.
controlRight
))
{
result
|=
RawKeyEventDataWeb
.
modifierControl
;
}
if
(
pressed
.
contains
(
LogicalKeyboardKey
.
altLeft
))
{
result
|=
RawKeyEventDataWeb
.
modifierAlt
;
}
if
(
pressed
.
contains
(
LogicalKeyboardKey
.
altRight
))
{
result
|=
RawKeyEventDataWeb
.
modifierAlt
;
}
if
(
pressed
.
contains
(
LogicalKeyboardKey
.
capsLock
))
{
result
|=
RawKeyEventDataWeb
.
modifierCapsLock
;
}
if
(
pressed
.
contains
(
LogicalKeyboardKey
.
numLock
))
{
result
|=
RawKeyEventDataWeb
.
modifierNumLock
;
}
if
(
pressed
.
contains
(
LogicalKeyboardKey
.
scrollLock
))
{
result
|=
RawKeyEventDataWeb
.
modifierScrollLock
;
}
return
result
;
}
static
int
_getMacOsModifierFlags
(
LogicalKeyboardKey
newKey
,
bool
isDown
)
{
int
result
=
0
;
final
Set
<
LogicalKeyboardKey
>
pressed
=
RawKeyboard
.
instance
.
keysPressed
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment