Skip to content
This repository has been archived by the owner on Feb 25, 2025. It is now read-only.

Commit

Permalink
Don't use sync*, as it is unimplemented in dart2wasm. (#38149)
Browse files Browse the repository at this point in the history
* Don't use sync*, as it is unimplemented in dart2wasm.

* Address Joshua's comments.

* Even more terse syntax, and change the name of the library
  • Loading branch information
eyebrowsoffire authored Dec 9, 2022
1 parent 030950f commit 89fd33c
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

// DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT
//
// This file is auto generated by flutter/engine:flutter/tools/gen_web_keyboard_layouts based on
// /~https://github.com/microsoft/vscode/tree/ab7ccc9e872dfcdfc429f8f2815109ec0ca926e3/src/vs/workbench/services/keybinding/browser/keyboardLayouts
// This file is auto generated by flutter/engine:flutter/tools/gen_web_keyboard_keymap based on
// /~https://github.com/microsoft/vscode/tree/422b581e3802e30cfb780c21d9cc1a2cd0c9f0aa/src/vs/workbench/services/keybinding/browser/keyboardLayouts
//
// Edit the following files instead:
//
// - Script: lib/main.dart
// - Templates: data/*.tmpl
//
// See flutter/engine:flutter/tools/gen_web_keyboard_layouts/README.md for more information.
// See flutter/engine:flutter/tools/gen_web_locale_keymap/README.md for more information.

/// Used in the final mapping indicating the logical key should be derived from
/// KeyboardEvent.keyCode.
Expand Down Expand Up @@ -100,16 +100,17 @@ bool isLetter(int charCode) {
///
/// This greatly reduces the entries needed in the final mapping.
int? heuristicMapper(String code, String key) {
// Digit code: return the digit.
// Digit code: return the digit by event code.
if (code.startsWith('Digit')) {
assert(code.length == 6);
return code.codeUnitAt(5); // The character immediately after 'Digit'
}
final int charCode = key.codeUnitAt(0);
// Non-ascii: return the goal (i.e. US mapping by event code).
if (key.length > 1 || !_isAscii(charCode)) {
return kLayoutGoals[code]?.codeUnitAt(0);
}
// Letter key: return the letter.
// Letter key: return the event key letter.
if (isLetter(charCode)) {
return key.toLowerCase().codeUnitAt(0);
}
Expand Down Expand Up @@ -167,22 +168,20 @@ class _StringStream {

Map<String, int> _unmarshallCodeMap(_StringStream stream) {
final int entryNum = stream.readIntAsVerbatim();
return Map<String, int>.fromEntries((() sync* {
for (int entryIndex = 0; entryIndex < entryNum; entryIndex += 1) {
yield MapEntry<String, int>(stream.readEventKey(), stream.readIntAsChar());
}
})());
return <String, int>{
for (int i = 0; i < entryNum; i++)
stream.readEventKey(): stream.readIntAsChar(),
};
}

/// Decode a key mapping data out of the string.
Map<String, Map<String, int>> unmarshallMappingData(String compressed) {
final _StringStream stream = _StringStream(compressed);
final int eventCodeNum = stream.readIntAsVerbatim();
return Map<String, Map<String, int>>.fromEntries((() sync* {
for (int eventCodeIndex = 0; eventCodeIndex < eventCodeNum; eventCodeIndex += 1) {
yield MapEntry<String, Map<String, int>>(stream.readEventCode(), _unmarshallCodeMap(stream));
}
})());
return <String, Map<String, int>>{
for (int i = 0; i < eventCodeNum; i++)
stream.readEventCode() : _unmarshallCodeMap(stream),
};
}

/// Data for [LocaleKeymap] on Windows.
Expand Down
4 changes: 2 additions & 2 deletions third_party/web_locale_keymap/test/test_cases.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

// DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT
//
// This file is auto generated by flutter/engine:flutter/tools/gen_web_keyboard_layouts based on
// This file is auto generated by flutter/engine:flutter/tools/gen_web_keyboard_keymap based on
// /~https://github.com/microsoft/vscode/tree/@@@COMMIT_ID@@@/src/vs/workbench/services/keybinding/browser/keyboardLayouts
//
// Edit the following files instead:
//
// - Script: lib/main.dart
// - Templates: data/*.tmpl
//
// See flutter/engine:flutter/tools/gen_web_keyboard_layouts/README.md for more information.
// See flutter/engine:flutter/tools/gen_web_keyboard_keymap/README.md for more information.

import 'package:test/test.dart';
import 'package:web_locale_keymap/web_locale_keymap.dart';
Expand Down
8 changes: 4 additions & 4 deletions tools/gen_web_locale_keymap/bin/gen_web_locale_keymap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import 'dart:io';

import 'package:args/args.dart';
import 'package:gen_web_keyboard_layouts/benchmark_planner.dart';
import 'package:gen_web_keyboard_layouts/common.dart';
import 'package:gen_web_keyboard_layouts/github.dart';
import 'package:gen_web_keyboard_layouts/layout_types.dart';
import 'package:gen_web_keyboard_keymap/benchmark_planner.dart';
import 'package:gen_web_keyboard_keymap/common.dart';
import 'package:gen_web_keyboard_keymap/github.dart';
import 'package:gen_web_keyboard_keymap/layout_types.dart';
import 'package:path/path.dart' as path;

const String kEnvGithubToken = 'GITHUB_TOKEN';
Expand Down
4 changes: 2 additions & 2 deletions tools/gen_web_locale_keymap/data/key_mappings.dart.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

// DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT
//
// This file is auto generated by flutter/engine:flutter/tools/gen_web_keyboard_layouts based on
// This file is auto generated by flutter/engine:flutter/tools/gen_web_keyboard_keymap based on
// @@@COMMIT_URL@@@
//
// Edit the following files instead:
//
// - Script: lib/main.dart
// - Templates: data/*.tmpl
//
// See flutter/engine:flutter/tools/gen_web_keyboard_layouts/README.md for more information.
// See flutter/engine:flutter/tools/gen_web_locale_keymap/README.md for more information.
@@@COMMON@@@

/// Data for [LocaleKeymap] on Windows.
Expand Down
4 changes: 2 additions & 2 deletions tools/gen_web_locale_keymap/data/test_cases.dart.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

// DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT
//
// This file is auto generated by flutter/engine:flutter/tools/gen_web_keyboard_layouts based on
// This file is auto generated by flutter/engine:flutter/tools/gen_web_keyboard_keymap based on
// /~https://github.com/microsoft/vscode/tree/@@@COMMIT_ID@@@/src/vs/workbench/services/keybinding/browser/keyboardLayouts
//
// Edit the following files instead:
//
// - Script: lib/main.dart
// - Templates: data/*.tmpl
//
// See flutter/engine:flutter/tools/gen_web_keyboard_layouts/README.md for more information.
// See flutter/engine:flutter/tools/gen_web_keyboard_keymap/README.md for more information.

import 'package:test/test.dart';
import 'package:web_locale_keymap/web_locale_keymap.dart';
Expand Down
18 changes: 8 additions & 10 deletions tools/gen_web_locale_keymap/lib/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,20 @@ class _StringStream {

Map<String, int> _unmarshallCodeMap(_StringStream stream) {
final int entryNum = stream.readIntAsVerbatim();
return Map<String, int>.fromEntries((() sync* {
for (int entryIndex = 0; entryIndex < entryNum; entryIndex += 1) {
yield MapEntry<String, int>(stream.readEventKey(), stream.readIntAsChar());
}
})());
return <String, int>{
for (int i = 0; i < entryNum; i++)
stream.readEventKey(): stream.readIntAsChar(),
};
}

/// Decode a key mapping data out of the string.
Map<String, Map<String, int>> unmarshallMappingData(String compressed) {
final _StringStream stream = _StringStream(compressed);
final int eventCodeNum = stream.readIntAsVerbatim();
return Map<String, Map<String, int>>.fromEntries((() sync* {
for (int eventCodeIndex = 0; eventCodeIndex < eventCodeNum; eventCodeIndex += 1) {
yield MapEntry<String, Map<String, int>>(stream.readEventCode(), _unmarshallCodeMap(stream));
}
})());
return <String, Map<String, int>>{
for (int i = 0; i < eventCodeNum; i++)
stream.readEventCode() : _unmarshallCodeMap(stream),
};
}

/*@@@ SHARED SEGMENT END @@@*/
Expand Down
2 changes: 1 addition & 1 deletion tools/gen_web_locale_keymap/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: gen_web_keyboard_layouts
name: gen_web_keyboard_keymap
description: Generates keyboard layouts for Web from external sources.

environment:
Expand Down

0 comments on commit 89fd33c

Please sign in to comment.