Skip to content

Commit

Permalink
Merge pull request #11603 from keymanapp/fix/web/kbd-proc-strictness-…
Browse files Browse the repository at this point in the history
…bugs

fix(web): fix keyboard-processing bugs uncovered by stricter TS settings 🔩
  • Loading branch information
jahorton authored Jun 3, 2024
2 parents b6207dc + 5abd621 commit b304069
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion common/web/input-processor/src/correctionLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function correctionKeyFilter(key: ActiveKeyBase): boolean {
return false;
// Attempt to filter out known non-output keys.
// Results in a more optimized distribution.
} else if(Codes.isKnownOSKModifierKey(key.baseKeyID)) {
} else if(Codes.isFrameKey(key.baseKeyID)) {
return false;
} else if(key.isPadding) { // to the user, blank / padding keys do not exist.
return false;
Expand Down
2 changes: 1 addition & 1 deletion common/web/input-processor/src/text/inputProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export default class InputProcessor {

// If it's a key that we 'optimize out' of our fat-finger correction algorithm,
// we MUST NOT trigger it for this keystroke.
let isOnlyLayerSwitchKey = Codes.isKnownOSKModifierKey(keyEvent.kName);
let isOnlyLayerSwitchKey = Codes.isFrameKey(keyEvent.kName);

// Best-guess stopgap for possible custom modifier keys.
// If a key (1) does not affect the context and (2) shifts the active layer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ export class Layouts {
static readonly dfltText='`1234567890-=\xA7~~qwertyuiop[]\\~~~asdfghjkl;\'~~~~~?zxcvbnm,./~~~~~ '
+'~!@#$%^&*()_+\xA7~~QWERTYUIOP{}\\~~~ASDFGHJKL:"~~~~~?ZXCVBNM<>?~~~~~ ';

static readonly DEFAULT_RAW_SPEC = {'F':'Tahoma', 'BK': Layouts.dfltText} as const;
// The function baked into keyboards by the current Web compiler creates an
// array of single-char strings for BK. Refer to
// developer/src/kmc-kmn/src/kmw-compiler/visual-keyboard-compiler.ts.
static readonly DEFAULT_RAW_SPEC = {'F':'Tahoma', 'BK': Layouts.dfltText.split('')} as const;

static modifierSpecials = {
'leftalt': '*LAlt*',
Expand Down
13 changes: 5 additions & 8 deletions common/web/keyboard-processor/src/text/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,22 @@ const Codes = {
[')!@#$%^&*(',':+<_>?~', '{|}"']
],

isKnownOSKModifierKey(keyID: string): boolean {
isFrameKey(keyID: string): boolean {
switch(keyID) {
// TODO: consider adding K_ALT, K_CTRL.
// Not currently here as they typically don't show up on mobile layouts.
case 'K_SHIFT':
case 'K_LOPT':
case 'K_ROPT':
case 'K_NUMLOCK': // Often used for numeric layers.
case 'K_CAPS':
return true;
default:
// 50000: start of the range defining key-codes for special frame-key symbols
// and specialized common layer-switching key IDs. See .keyCodes above.
if(Codes.keyCodes[keyID] >= 50000) { // A few are used by `sil_euro_latin`.
return true; // is a 'K_' key defined for layer shifting or 'control' use.
}
// Refer to text/codes.ts - these are Keyman-custom "keycodes" used for
// layer shifting keys. To be safe, we currently let K_TABBACK and
// K_TABFWD through, though we might be able to drop them too.
const code = Codes[keyID];
if(code > 50000 && code < 50011) {
return true;
}
}

return false;
Expand Down
6 changes: 3 additions & 3 deletions common/web/keyboard-processor/src/text/kbdInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -938,9 +938,9 @@ export default class KeyboardInterface extends KeyboardHarness {
if(systemId == SystemStoreIDs.TSS_LAYER && this.activeDevice.touchable) {
// Denote the changed store as part of the matched rule's behavior.
this.ruleBehavior.setStore[systemId] = strValue;
} else {
return false;
}
return true;
}
return false;
}

/**
Expand Down

0 comments on commit b304069

Please sign in to comment.