mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-15 04:54:05 +09:00
working cangjie IME implementation
This commit is contained in:
@@ -4,16 +4,16 @@ let states = {"keylayouts":[[""],[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
["0",")"],
|
||||
["1","!"],
|
||||
["0",")"],
|
||||
["1","!"],
|
||||
["2","@"],
|
||||
["3","#"],
|
||||
["4","$"],
|
||||
["4","¥"],
|
||||
["5","%"],
|
||||
["6","^"],
|
||||
["6","…"],
|
||||
["7","&"],
|
||||
["8","*"],
|
||||
["9","("],
|
||||
["8","×"],
|
||||
["9","("],
|
||||
["*"],
|
||||
["#"],
|
||||
[undefined],
|
||||
@@ -52,26 +52,26 @@ let states = {"keylayouts":[[""],[undefined],
|
||||
["x","X"],
|
||||
["y","Y"],
|
||||
["z","Z"],
|
||||
[",","<"],
|
||||
[".",">"],
|
||||
[",","《"],
|
||||
["。","》"],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[" "],
|
||||
[" ", " "],
|
||||
[undefined],
|
||||
[undefined],
|
||||
[undefined],
|
||||
["\n"],
|
||||
["\x08"],
|
||||
["`","~"],
|
||||
["-","_"],
|
||||
["·","~"],
|
||||
["-","—"],
|
||||
["=","+"],
|
||||
["[","{"],
|
||||
["]","}"],
|
||||
["\\","|"],
|
||||
[";",":"],
|
||||
["「","{"],
|
||||
["」","}"],
|
||||
["、","|"],
|
||||
[";",":"],
|
||||
["'",'"'],
|
||||
["/","?"],
|
||||
[undefined],
|
||||
@@ -263,8 +263,12 @@ let reset = () => {
|
||||
states.buf = ""
|
||||
states.candidates = ""
|
||||
}
|
||||
//let bufDebugStringify = (buf) => [0,1,2].map(i => (buf[i] == undefined) ? "·" : `\\u${buf[i].codePointAt(0).toString(16).toUpperCase()}`).join(' ')
|
||||
let bufDebugStringify = (buf) => [0,1,2].map(i => (buf[i] == undefined) ? "·" : `${buf[i]}`).join(' ')
|
||||
let getCandidatesUsingBuf = () => {
|
||||
states.candidates = states.dict.get(states.buf) // comma-separated values
|
||||
states.code = 1 + (states.candidates.length == 0)
|
||||
// console.log(`cangjie in, buf: ${states.buf}, candidates: ${states.candidates}`)
|
||||
return `${states.buf},${states.candidates}`
|
||||
}
|
||||
return Object.freeze({"n":"五倉正體 Qwerty","states":states,"c":"CuriousTo\uA75Bvald, 倉頡之友 。馬來西亞 http://www.chinesecj.com",
|
||||
// return: [displayed output, composed output]
|
||||
"accept":(headkey,shiftin,altgrin)=>{
|
||||
@@ -279,31 +283,32 @@ return Object.freeze({"n":"五倉正體 Qwerty","states":states,"c":"CuriousTo\u
|
||||
reset()
|
||||
return ['', selection || raw]
|
||||
}
|
||||
else if (97 <= cjkeyAsc && cjkeyAsc <= 122 || cjkeyAsc == 42) {
|
||||
else if (1 == states.code && " " == cjkey) {
|
||||
let ret = (1 == states.code) ? states.candidates[0] : (''+states.buf)
|
||||
reset()
|
||||
return ['', ret]
|
||||
}
|
||||
else if (states.code < 2 && states.buf.length < 5 && 97 <= cjkeyAsc && cjkeyAsc <= 122 || cjkeyAsc == 42) {
|
||||
states.buf += cjkey
|
||||
|
||||
states.candidates = states.dict.get(states.buf) // comma-separated values
|
||||
states.code = 1 + (states.candidates.length == 0)
|
||||
|
||||
console.log(`cangjie in, buf: ${states.buf}, candidates: ${states.candidates}`)
|
||||
|
||||
return [`${states.buf},${states.candidates}`, '']
|
||||
return [getCandidatesUsingBuf(), '']
|
||||
}
|
||||
else {
|
||||
states.code = 0
|
||||
return ['', ''+states.buf+cjkey]
|
||||
let ret = ''+states.buf+cjkey
|
||||
reset()
|
||||
return ['', ret]
|
||||
}
|
||||
|
||||
return ['', cjkey]
|
||||
},
|
||||
"backspace":()=>{
|
||||
if (states.buf.length <= 1) {
|
||||
reset()
|
||||
return ''
|
||||
}
|
||||
|
||||
|
||||
return ''
|
||||
states.buf = states.buf.substring(0, states.buf.length - 1)
|
||||
return getCandidatesUsingBuf()
|
||||
},
|
||||
"end":()=>{
|
||||
// console.log(`end composing`)
|
||||
let ret = ''+states.buf
|
||||
let ret = (1 == states.code) ? states.candidates[0] : (''+states.buf)
|
||||
reset()
|
||||
return ret
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user