From be9fe1e3a38c4c90a0b2853854c72cb4e872bbb0 Mon Sep 17 00:00:00 2001 From: remi Date: Sat, 7 May 2022 12:33:35 +0200 Subject: [PATCH] finished?! --- ime.js | 86 ++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 54 insertions(+), 32 deletions(-) diff --git a/ime.js b/ime.js index 9fb9a87..eb8f49d 100644 --- a/ime.js +++ b/ime.js @@ -17,6 +17,30 @@ window.onload = () => { }); } +function imePush() { + //basically equavlient to pressing enter. + if (selected == -1) { + if (currentWord.join() == "") { //blame js :) + let s = document.createElement("p"); + s.innerText = input.join(""); + document.body.appendChild(s); + input = []; + selected = -1; + } else { + input.push(currentWord); + currentWord = []; + } + imeReset(); + } else { + if (selected+1 >= input.length) { + selected = -1; + } else { + selected += 1; + } + imeReset(true); + } +} + function imeDown(keyEvent, inputField) { keyEvent.preventDefault(); switch (keyEvent.key) { @@ -38,25 +62,7 @@ function imeDown(keyEvent, inputField) { } break; case "Enter": - if (selected == -1) { - if (currentWord.join() == "") { //blame js :) - let s = document.createElement("p"); - s.innerText = input.join(""); - document.body.appendChild(s); - input = []; - selected = -1; - } else { - input.push(currentWord); - currentWord = []; - } - } else { - if (selected+1 >= input.length) { - selected = -1; - } else { - selected += 1; - } - } - imeReset(); + imePush() break; case "Space": //adds a ', on second press . an actual space @@ -139,7 +145,7 @@ function imeMove(direction) { } break; } - imeReset(); + imeReset(true); } let inputState = 0; //STARTING, COMPOSTING, TRAILING, Fucking Nothing, ...cleanup @@ -209,17 +215,18 @@ function debugInput(key) { console.log("------------------------------") } -function imeReset() { +function imeReset(soft = false) { stateState = 0; inputState = 0; inputFull = []; inputCurrent = ""; - if (selected == -1) { - currentWord = []; - } else { - input[selected] = []; + if (!soft) { + if (selected == -1) { + currentWord = []; + } else { + input[selected] = []; + } } - } function imeInfo(decHex) { @@ -386,10 +393,13 @@ function imeInput(key) { if (hVowelsK.includes(key)) { if (stateState == 1 && inputCurrent != "") { inputFull.pop(); - inputFull.push(getUnicodeConsonant(inputCurrent, key)); + let ic = inputCurrent; + let k = key; + imePush(); + inputFull.pop(); + inputFull.push(getUnicodeConsonant(ic, k)); inputCurrent = ""; - //reset state??? - stateState = 0; + inputState = 2; } else { inputFull.push(getUnicodeVowel(key, "trailing")); inputCurrent = ""; @@ -397,16 +407,28 @@ function imeInput(key) { } } else { inputFull.push(getUnicodeConsonant(key, "trailing")); - if (stateState == 0) inputCurrent = key; + inputCurrent = key; stateState += 1; } if (stateState == 2) { stateState = 0; inputState = 3; - } + }; break; case 3: //go to next word uwu - //todo :) + if (key != "") { + inputFull.pop(); + let ic = inputCurrent; + let k = key; + imePush(); + inputFull.pop(); + inputFull.push(getUnicodeConsonant(ic, k)); + inputCurrent = ""; + inputState = 2; + } else { + imePush(); + imeInput(key); + } break; } } \ No newline at end of file