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
3af6b2f6
Unverified
Commit
3af6b2f6
authored
Dec 07, 2021
by
Tong Mu
Committed by
GitHub
Dec 07, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[macOS] RawKeyboardDataMacos properly handles multi-char characters (#94432)
* Impl * Macos
parent
e4a1d3e1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
18 deletions
+32
-18
raw_keyboard_macos.dart
packages/flutter/lib/src/services/raw_keyboard_macos.dart
+18
-18
raw_keyboard_test.dart
packages/flutter/test/services/raw_keyboard_test.dart
+14
-0
No files found.
packages/flutter/lib/src/services/raw_keyboard_macos.dart
View file @
3af6b2f6
...
...
@@ -85,25 +85,25 @@ class RawKeyEventDataMacOs extends RawKeyEventData {
return
knownKey
;
}
// If this key is printable, generate the LogicalKeyboardKey from its
// Unicode value. Control keys such as ESC, CTRL, and SHIFT are not
// printable. HOME, DEL, arrow keys, and function keys are considered
// modifier function keys, which generate invalid Unicode scalar values.
if
(
keyLabel
.
isNotEmpty
&&
!
LogicalKeyboardKey
.
isControlCharacter
(
keyLabel
)
&&
!
_isUnprintableKey
(
keyLabel
))
{
// Given that charactersIgnoringModifiers can contain a String of
// arbitrary length, limit to a maximum of two Unicode scalar values. It
// is unlikely that a keyboard would produce a code point bigger than 32
// bits, but it is still worth defending against this case.
assert
(
charactersIgnoringModifiers
.
length
<=
2
);
int
codeUnit
=
charactersIgnoringModifiers
.
codeUnitAt
(
0
);
if
(
charactersIgnoringModifiers
.
length
==
2
)
{
final
int
secondCode
=
charactersIgnoringModifiers
.
codeUnitAt
(
1
);
codeUnit
=
(
codeUnit
<<
16
)
|
secondCode
;
// If this key is a single printable character, generate the
// LogicalKeyboardKey from its Unicode value. Control keys such as ESC,
// CTRL, and SHIFT are not printable. HOME, DEL, arrow keys, and function
// keys are considered modifier function keys, which generate invalid
// Unicode scalar values. Multi-char characters are also discarded.
int
?
character
;
if
(
keyLabel
.
isNotEmpty
)
{
final
List
<
int
>
codePoints
=
keyLabel
.
runes
.
toList
();
if
(
codePoints
.
length
==
1
&&
// Ideally we should test whether `codePoints[0]` is in the range.
// Since LogicalKeyboardKey.isControlCharacter and _isUnprintableKey
// only tests BMP, it is fine to test keyLabel instead.
!
LogicalKeyboardKey
.
isControlCharacter
(
keyLabel
)
&&
!
_isUnprintableKey
(
keyLabel
))
{
character
=
codePoints
[
0
];
}
final
int
keyId
=
LogicalKeyboardKey
.
unicodePlane
|
(
codeUnit
&
LogicalKeyboardKey
.
valueMask
);
}
if
(
character
!=
null
)
{
final
int
keyId
=
LogicalKeyboardKey
.
unicodePlane
|
(
character
&
LogicalKeyboardKey
.
valueMask
);
return
LogicalKeyboardKey
.
findKeyByKeyId
(
keyId
)
??
LogicalKeyboardKey
(
keyId
);
}
...
...
packages/flutter/test/services/raw_keyboard_test.dart
View file @
3af6b2f6
...
...
@@ -1475,6 +1475,20 @@ void main() {
expect
(
data
.
logicalKey
,
equals
(
LogicalKeyboardKey
.
arrowLeft
));
});
test
(
'Multi-char keyboard keys are correctly translated'
,
()
{
final
RawKeyEvent
leftArrowKey
=
RawKeyEvent
.
fromMessage
(
const
<
String
,
dynamic
>{
'type'
:
'keydown'
,
'keymap'
:
'macos'
,
'keyCode'
:
0x00000000
,
'characters'
:
'án'
,
'charactersIgnoringModifiers'
:
'án'
,
'modifiers'
:
0
,
});
final
RawKeyEventDataMacOs
data
=
leftArrowKey
.
data
as
RawKeyEventDataMacOs
;
expect
(
data
.
physicalKey
,
equals
(
PhysicalKeyboardKey
.
keyA
));
expect
(
data
.
logicalKey
,
equals
(
const
LogicalKeyboardKey
(
0x1400000000
)));
});
test
(
'data.toString'
,
()
{
expect
(
RawKeyEvent
.
fromMessage
(
const
<
String
,
dynamic
>{
'type'
:
'keydown'
,
...
...
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