Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(web): fix keyboard-processing bugs uncovered by stricter TS settings 🔩 #11603

Merged
merged 6 commits into from
Jun 3, 2024

Conversation

jahorton
Copy link
Contributor

Originally part of #11424, these changes address bugs that were uncovered thanks to stricter TS settings. There are three in total, but they're in the same region of code and are all quite small, so I lumped 'em together.

@keymanapp-test-bot skip

// 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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From an old keyboard (viewable here):

BK: new Array("`","1","2","3","4","5","6","7","8","9","0","-","=","","","","q","w","e","r","t","y","u","i","o","p","[","]","\\","","","","a","s","d","f","g","h","j","k","l",";","'","","","","","","\\","z","x","c","v","b","n","m",",",".","/","","","","",""," ","~","!","@","#","$","%","^","&","*","(",")","_","+","","","","Q","W","E","R","T","Y","U","I","O","P","{","}","|","","","","A","S","D","F","G","H","J","K","L",":","\"","","","","","","|","Z","X","C","V","B","N","M","<",">","?","","","","",""," ","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""," ")

From the output generated by modern compilers when run live (via khmer_angkor):

(130) ['«', '១', '២', '៣', '៤', '៥', '៦', '៧', '៨', '៩', '០', 'ឥ', 'ឲ', '', '', '', 'ឆ', '', '', 'រ', 'ត', 'យ', '', '', '', 'ផ', '', 'ឪ', 'ឮ', '', '', '', '', 'ស', 'ដ', 'ថ', 'ង', 'ហ', '', 'ក', 'ល', '', '', '', '', '', '', '', '', 'ឋ', 'ខ', 'ច', 'វ', 'ប', 'ន', 'ម', '', '។', '', '', '', '', '', '', '​', '»', '!', 'ៗ', '"', '៛', '%', '', '', '', '(', ')', '', '=', '', '', '', 'ឈ', '', '', 'ឬ', 'ទ', '', '', '', '', 'ភ', '', 'ឧ', 'ឭ', '', '', '', '', '', 'ឌ', …]

It is technically OK in JavaScript to index a string as if it were an array, which is why things have been working. TS strictness settings don't like it, though.

@@ -86,7 +86,7 @@ const Codes = {
[')!@#$%^&*(',':+<_>?~', '{|}"']
],

isKnownOSKModifierKey(keyID: string): boolean {
isKeyNotCorrected(keyID: string): boolean {
Copy link
Contributor Author

@jahorton jahorton May 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the name for two reasons:

  1. This highlights the limited uses of the method.
  2. Given that the only use is to determine what keys we don't fat-finger correct, and that K_TAB + K_TABFWD are being included... well, K_TAB isn't a modifier key, so the name isn't quite right.

Comment on lines 98 to -107
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;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once I stopped and looked at this... "wait, why do we have two near-identical checks"? And... "when did this happen?"

The answer to the latter question: it happened in #7242. I don't know what I was thinking then. It's clear we should only have one of the two.

Granted, settling on the one that I did kind of implies we should also ignore K_TAB for consistency. (I haven't made this change yet, though.)

@@ -938,6 +938,7 @@ 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;
return true;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note line 929, which says we should have been doing this all along.

@jahorton jahorton marked this pull request as ready for review May 29, 2024 03:35
@jahorton jahorton requested a review from mcdurdin as a code owner May 29, 2024 03:35
Copy link
Member

@mcdurdin mcdurdin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be three separate pull requests -- they are three unrelated bugs.

The three bug fix titles could have been:

  1. fix(web): [keyboard].KV.BK should always be an array but default fallback was providing a string
  2. refactor(web): Remove dead code in isKnownOSKModifierKey and rename it to isKeyNotCorrected
  3. fix(web): always return true or false for KSETS (setStore)

In my analysis, none of the three changes have any end-user impact.

  1. as you noted, [keyboard].KV.BK as string or array had basically the same outcome, but would be a trap for future maintainers
  2. there is a question you ask regarding isKeyNotCorrected which probably could turn into its own discussion:

    Granted, settling on the one that I did kind of implies we should also ignore K_TAB for consistency. (I haven't made this change yet, though.)

  3. keyboards do not use the return value from KSETS:
    Result += nlt+`k.KSETS(${rec.SetSystemStore.dwSystemID},`+
    `this.s${JavaScript_Name(rec.SetSystemStore.StoreIndex, rec.SetSystemStore.Store.dpName)},t);`; // I3681

Generally, including Not in a function name is a code smell. A better name may be isFrameKey?

Apart from that, LGTM. I guess I will approve this PR this time, but let's try and get into the habit of fixing one bug at a time in a PR.

common/web/keyboard-processor/src/text/kbdInterface.ts Outdated Show resolved Hide resolved
@github-actions github-actions bot added web/ and removed web/ labels May 30, 2024
@github-actions github-actions bot added web/ and removed web/ labels May 30, 2024
@github-actions github-actions bot added web/ and removed web/ labels May 31, 2024
@jahorton jahorton changed the title fix(web): keyboard-processing bugs uncovered by stricter TS settings 🔩 fix(web): fix keyboard-processing bugs uncovered by stricter TS settings 🔩 Jun 3, 2024
Base automatically changed from refactor/web/typed-property-transplantation to master June 3, 2024 03:55
@jahorton jahorton merged commit b304069 into master Jun 3, 2024
19 checks passed
@jahorton jahorton deleted the fix/web/kbd-proc-strictness-bugs branch June 3, 2024 03:55
@keyman-server
Copy link
Collaborator

Changes in this pull request will be available for download in Keyman version 18.0.47-alpha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants