mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-11 03:15:33 +00:00
refactor(web/engine): more PR review addressing
This commit is contained in:
parent
50dbccf550
commit
e7a1496fcb
2 changed files with 21 additions and 10 deletions
|
|
@ -4,6 +4,12 @@
|
|||
/// <reference path="keyEvent.ts" />
|
||||
|
||||
namespace com.keyman.text {
|
||||
export enum EmulationKeystrokes {
|
||||
Space = ' ',
|
||||
Enter = '\n',
|
||||
Backspace = '\b'
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines a collection of static library functions that define KeymanWeb's default (implied) keyboard rule behaviors.
|
||||
*/
|
||||
|
|
@ -141,18 +147,21 @@ namespace com.keyman.text {
|
|||
* Codes matched here generally have default implementations when in a browser but require emulation
|
||||
* for 'synthetic' `OutputTarget`s like `Mock`s, which have no default text handling.
|
||||
*/
|
||||
public static forSpecialEmulation(Lkc: KeyEvent): string {
|
||||
public static forSpecialEmulation(Lkc: KeyEvent): EmulationKeystrokes {
|
||||
let code = DefaultOutput.codeForEvent(Lkc);
|
||||
|
||||
switch(code) {
|
||||
case Codes.keyCodes['K_BKSP']:
|
||||
return '\b';
|
||||
return EmulationKeystrokes.Backspace;
|
||||
case Codes.keyCodes['K_ENTER']:
|
||||
return '\n';
|
||||
return EmulationKeystrokes.Enter;
|
||||
// (Probably) only here for legacy reasons; it's always been handled alongside the other two.
|
||||
case Codes.keyCodes['K_SPACE']:
|
||||
return ' ';
|
||||
return EmulationKeystrokes.Space;
|
||||
// case Codes.keyCodes['K_DEL']:
|
||||
// return '\u007f'; // 127, ASCII / Unicode control code for DEL.
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ namespace com.keyman.text {
|
|||
|
||||
let matched = false;
|
||||
var char = '';
|
||||
var special: EmulationKeystrokes;
|
||||
if(usingOSK || outputTarget.isSynthetic) {
|
||||
matched = true; // All the conditions below result in matches until the final else, which restores the expected default
|
||||
// if no match occurs.
|
||||
|
|
@ -63,22 +64,23 @@ namespace com.keyman.text {
|
|||
|
||||
// We'd rather let the browser handle these keys, but we're using emulated keystrokes, forcing KMW
|
||||
// to emulate default behavior here.
|
||||
} else if(char = DefaultOutput.forSpecialEmulation(Lkc)) {
|
||||
switch(char) {
|
||||
case '\b':
|
||||
} else if(special = DefaultOutput.forSpecialEmulation(Lkc)) {
|
||||
switch(special) {
|
||||
case EmulationKeystrokes.Backspace:
|
||||
keyman.interface.defaultBackspace(outputTarget);
|
||||
break;
|
||||
case '\n':
|
||||
case EmulationKeystrokes.Enter:
|
||||
outputTarget.handleNewlineAtCaret();
|
||||
break;
|
||||
case ' ':
|
||||
case EmulationKeystrokes.Space:
|
||||
keyman.interface.output(0, outputTarget, ' ');
|
||||
break;
|
||||
// case '\u007f': // K_DEL
|
||||
// // For (possible) future implementation.
|
||||
// // Would recommend (conceptually) equaling K_RIGHT + K_BKSP, the former of which would technically be a 'command'.
|
||||
default:
|
||||
ruleBehavior.errorLog = "Unexpected 'special emulation' character (\\u" + char.kmwCharCodeAt(0).toString(16) + ") went unhandled!";
|
||||
// In case we extend the allowed set, but forget to implement its handling case above.
|
||||
ruleBehavior.errorLog = "Unexpected 'special emulation' character (\\u" + (special as String).kmwCharCodeAt(0).toString(16) + ") went unhandled!";
|
||||
}
|
||||
} else {
|
||||
// Back to the standard default, pending normal matching.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue