working backspace button :)
This commit is contained in:
parent
c01ebee0ae
commit
ad22fd715e
148
ime.js
148
ime.js
@ -22,17 +22,15 @@ function imeDown(keyEvent, inputField) {
|
||||
switch (keyEvent.key) {
|
||||
case "Backspace":
|
||||
if (selected == -1) {
|
||||
let latest = input[input.length]
|
||||
console.log(latest);
|
||||
|
||||
|
||||
if (currentWord.join("") == "") {
|
||||
currentWord = input.pop() || [];
|
||||
} else {
|
||||
currentWord.pop();
|
||||
imeRestore(currentWord);
|
||||
// currentWord.pop();
|
||||
}
|
||||
} else {
|
||||
input[selected].pop();
|
||||
imeRestore(input[selected]);
|
||||
// input[selected].pop();
|
||||
if (input[selected].join("") == "") {
|
||||
input.splice(selected,1);
|
||||
imeMove("left");
|
||||
@ -190,8 +188,17 @@ function getUnicodeConsonant(consonant, scv) {
|
||||
return String.fromCharCode(parseInt("E" + hConsonants[consonant] + "" + scv, 16));
|
||||
}
|
||||
|
||||
function inverse(obj){
|
||||
var retobj = {};
|
||||
for(var key in obj){
|
||||
retobj[obj[key]] = key;
|
||||
}
|
||||
return retobj;
|
||||
}
|
||||
|
||||
let hVowelsK = Object.keys(hVowels)
|
||||
let hConsonantsK = Object.keys(hConsonants);
|
||||
let hConsonantsR = inverse(hConsonants);
|
||||
|
||||
function debugInput(key) {
|
||||
console.log("pre "+key+": inputstate - "+inputState +", statestate - "+ stateState);
|
||||
@ -207,6 +214,128 @@ function imeReset() {
|
||||
inputState = 0;
|
||||
inputFull = [];
|
||||
inputCurrent = "";
|
||||
if (selected == -1) {
|
||||
currentWord = [];
|
||||
} else {
|
||||
input[selected] = [];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function imeInfo(decHex) {
|
||||
try {
|
||||
let hex = decHex.codePointAt(0).toString(16);
|
||||
hex[1] = parseInt(hex[1], 16);
|
||||
hex[2] = parseInt(hex[2], 16);
|
||||
hex[3] = parseInt(hex[3], 16);
|
||||
let ka = (hex[1] == 0 && hex[2] == 0) ? "a" : "k";
|
||||
if (ka == "k") {
|
||||
if (hex[3] == 1) {
|
||||
//trailing
|
||||
return([ka,"trailing"])
|
||||
} else if (hex[3] == 0) {
|
||||
//standalone
|
||||
//full reset / no restore necessary
|
||||
return([ka,"standalone"])
|
||||
} else {
|
||||
//composing
|
||||
return([ka,"composing"])
|
||||
}
|
||||
} else {
|
||||
if (hex[3] <= 8) {
|
||||
//standalone
|
||||
return([ka,"standalone"])
|
||||
} else {
|
||||
//trailing
|
||||
return([ka,"trailing"])
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
function imeChange(inState, stState, pop, array) {
|
||||
inputState = inState;
|
||||
stateState = stState;
|
||||
if (pop) {
|
||||
array.pop();
|
||||
}
|
||||
inputFull = array;
|
||||
}
|
||||
|
||||
function imeRestore(array) {
|
||||
let hex = array[array.length-1].codePointAt(0).toString(16);
|
||||
hex[1] = parseInt(hex[1], 16);
|
||||
hex[2] = parseInt(hex[2], 16);
|
||||
hex[3] = parseInt(hex[3], 16);
|
||||
let previous = imeInfo(array[array.length-2])[1];
|
||||
let ka = (hex[1] == 0 && hex[2] == 0) ? "a" : "k";
|
||||
if (ka == "k") {
|
||||
if (hex[3] == 1) {
|
||||
//trailing
|
||||
if (previous == "trailing") {
|
||||
//trailing twice
|
||||
console.log("2.1");
|
||||
imeChange(2,1,true,array);
|
||||
} else {
|
||||
//trailing once
|
||||
console.log("2.0");
|
||||
imeChange(2,0,true,array);
|
||||
}
|
||||
} else if (hex[3] == 0) {
|
||||
console.log(array.length);
|
||||
if (array.length != 1) {
|
||||
//0.1, i think?
|
||||
console.log("0.1");
|
||||
imeChange(0,1,true,array);
|
||||
} else {
|
||||
//standalone
|
||||
console.log("full reset");
|
||||
imeReset();
|
||||
}
|
||||
} else {
|
||||
//composing
|
||||
if (previous == "standalone") {
|
||||
//0.1??
|
||||
//recreate?? last digit???
|
||||
let c = hConsonantsR[[hex[1], hex[2]].join("").toUpperCase()];
|
||||
array.pop();
|
||||
array.push(getUnicodeConsonant(c, "standalone"));
|
||||
inputCurrent = c;
|
||||
|
||||
console.log("0.1");
|
||||
imeChange(0,1,false,array);
|
||||
} else {
|
||||
//0.2???? fuck it lets try and find out ig
|
||||
//recreate?? last digit???
|
||||
let c = hConsonantsR[[hex[1], hex[2]].join("").toUpperCase()];
|
||||
array.pop();
|
||||
array.push(getUnicodeConsonant(c, "standalone"));
|
||||
inputCurrent = c;
|
||||
|
||||
console.log("0.2");
|
||||
imeChange(0,2,false,array);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (hex[3] <= 8) {
|
||||
//standalone
|
||||
console.log("full reset");
|
||||
imeReset();
|
||||
} else {
|
||||
//trailing
|
||||
if (previous == "trailing") {
|
||||
//trailing twice
|
||||
console.log("2.1");
|
||||
imeChange(2,1,true,array);
|
||||
} else {
|
||||
//trailing once
|
||||
console.log("2.0");
|
||||
imeChange(2,0,true,array);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function imeInput(key) {
|
||||
@ -261,11 +390,8 @@ function imeInput(key) {
|
||||
inputState = 3;
|
||||
}
|
||||
break;
|
||||
case 3: //do nothing (i.e "waiting 4 u 2 hit enter")
|
||||
break;
|
||||
case 4: //cleanup (reset vars)
|
||||
stateState = 0;
|
||||
inputCurrent = "";
|
||||
case 3: //go to next word uwu
|
||||
//todo :)
|
||||
break;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user