From 2f58e9eda602191c493efdfd00e00718e2adb09b Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Sun, 16 Nov 2025 15:04:34 +0000 Subject: [PATCH 1/2] parameterize check method --- inputMethods.ts | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/inputMethods.ts b/inputMethods.ts index 29fb9d8..23d566d 100644 --- a/inputMethods.ts +++ b/inputMethods.ts @@ -271,22 +271,26 @@ namespace microgui { kb.appendText(".") } // END OF: Decimal point - const __kbBehaviourNumericEnter: KeyboardBtnFn = (btn: Button, kb: IKeyboard) => { // Enter - const txt = kb.getText(); - const len = txt.length; - const lenRule = txt[len - 1] != "-"; - const noDecimalEnding = txt[len - 1] != "."; // Illegal: 0. , -0. , -10. Okay: -0.00.. and 0.000 (becomes 0 later) - - if (len > 0 && lenRule && noDecimalEnding) { // Last rule could be removed, casting "1." to number is valid. - // Turn -0 and -0.000... into 0 before returning - const txtAsNum: number = +txt; - if (txtAsNum == 0 || txtAsNum == -0) - kb.setText("0") - kb.nextScene() - } else { - kb.shakeText() - } - } // END OF: ENTER + const get__kbBehaviourNumericEnter = (layout: KeyboardLayouts) => { + const __kbBehaviourNumericEnter: KeyboardBtnFn = (btn: Button, kb: IKeyboard) => { // Enter + const txt = kb.getText(); + const len = txt.length; + const lenRule = txt[len - 1] != "-"; + const noDecimalEnding = txt[len - 1] != "."; // Illegal: 0. , -0. , -10. Okay: -0.00.. and 0.000 (becomes 0 later) + + if (len > 0 && lenRule && noDecimalEnding) { // Last rule could be removed, casting "1." to number is valid. + // Turn -0 and -0.000... into 0 before returning + const txtAsNum: number = +txt; + if (txtAsNum == 0 || txtAsNum == -0) + kb.setText(layout == KeyboardLayouts.NUMERIC ? "0" : "1") + kb.nextScene() + } else { + kb.shakeText() + } + return __kbBehaviourNumericDecimal + } // END OF: ENTER + return __kbBehaviourNumericEnter + } function __keyboardLayout(layout: KeyboardLayouts, del = false): KeyboardLayoutData { switch (layout) { @@ -331,7 +335,7 @@ namespace microgui { defaultBtnBehaviour: __kbBehaviourNumericDefault, specialBtnBehaviours: [ { btnRow: 0, btnCol: 3, behaviour: (btn: Button, kb: IKeyboard) => kb.deletePriorCharacters(1) }, // Backspace - { btnRow: 2, btnCol: 4, behaviour: (b: Button, kb: IKeyboard) => __kbBehaviourNumericEnter(b, kb) } + { btnRow: 2, btnCol: 4, behaviour: (b: Button, kb: IKeyboard) => get__kbBehaviourNumericEnter(layout)(b, kb) } ] } if (layout == KeyboardLayouts.NUMERIC) { From 3ae709f6a4b6a7097df421e56e2a4bb93997e7d6 Mon Sep 17 00:00:00 2001 From: Thomas Ball Date: Sun, 16 Nov 2025 15:12:48 +0000 Subject: [PATCH 2/2] try this --- inputMethods.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/inputMethods.ts b/inputMethods.ts index 23d566d..bc4cef4 100644 --- a/inputMethods.ts +++ b/inputMethods.ts @@ -277,8 +277,10 @@ namespace microgui { const len = txt.length; const lenRule = txt[len - 1] != "-"; const noDecimalEnding = txt[len - 1] != "."; // Illegal: 0. , -0. , -10. Okay: -0.00.. and 0.000 (becomes 0 later) + const noZeroPosInt = txt === "0" - if (len > 0 && lenRule && noDecimalEnding) { // Last rule could be removed, casting "1." to number is valid. + if (len > 0 && (layout == KeyboardLayouts.NUMERIC && lenRule && noDecimalEnding || + layout == KeyboardLayouts.NUMERIC_POSITIVE_INTEGER && noZeroPosInt)) { // Last rule could be removed, casting "1." to number is valid. // Turn -0 and -0.000... into 0 before returning const txtAsNum: number = +txt; if (txtAsNum == 0 || txtAsNum == -0)