From: handa Date: Sun, 21 Feb 2010 23:39:28 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: ALPHA~51 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=068ab538bbcee88357aa4787fb15833a005c1075;p=m17n%2Fm17n-lib-js.git *** empty log message *** --- diff --git a/xex.html b/xex.html index 872e515..618db49 100644 --- a/xex.html +++ b/xex.html @@ -12,19 +12,16 @@ - -

m17n-lib input method in Javascript

-

textarea

+ +

m17n-lib input method in Javascript

+

textarea

-

text

-
-
-

debug Info

+
text
+
debug Info
- - - + + +
keykeycodestatuskeyseqrange
down0
press0
keykeycodestatuskeyseqpreedit
down0
press0
-
-
+ diff --git a/xex.js b/xex.js index a726a77..8be7f9d 100644 --- a/xex.js +++ b/xex.js @@ -1579,30 +1579,37 @@ MIM.im_domain.DefType (MIM.State.prototype); { var out = this.keymap.Lookup (this.keys, this.key_head); var sub = out.map; + var branch_actions = this.state.keymap.actions; - alert ('handling ' + this.keys.val[this.key_head]); + MIM.log ('handling ' + this.keys.val[this.key_head] + + ' in ' + this.state.name); this.key_head = out.index; if (sub != this.keymap) { + restore_state.call (this); this.keymap = sub; - alert ('submap found, taking map actions:' + sub.actions); + MIM.log ('submap found'); if (this.keymap.actions != null) { + MIM.log ('taking map actions:'); if (! this.take_actions (this.keymap.actions)) return false; } else if (this.keymap.submaps != null) { + MIM.log ('no map actions, inserting key:'); for (var i = this.state_key_head; i < this.key_head; i++) this.preedit_replace (this.cursor_pos, this.cursor_pos, this.keys.val[i].key, null); } if (this.keymap.submaps == null) { + MIM.log ('terminal:'); if (this.keymap.branch_actions != null) { - if (! this.take_actions (this.keymap.branch_actions)) + MIM.log ('branch actions:'); + if (! this.take_actions (branch_actions)) return false; } if (this.keymap != this.state.keymap) @@ -1611,10 +1618,12 @@ MIM.im_domain.DefType (MIM.State.prototype); } else { + MIM.log ("no submap"); var current_state = this.state; - if (this.keymap.branch_actions != null) + if (branch_actions) { + MIM.log ("branch actions"); if (! this.take_actions (this.keymap.branch_actions)) return false; } @@ -1815,10 +1824,13 @@ MIM.im_domain.DefType (MIM.State.prototype); { if (state == null) { + MIM.log ("shifting back to previous"); if (this.prev_state == null) return; state = this.prev_state; } + else + MIM.log ("shifting to " + state.name); if (state == this.initial_state) { @@ -1965,6 +1977,14 @@ MIM.add_event_listener = function (e) { listener.call (target, e || window.event); }; }); +MIM.log = function (msg) +{ + var node = document.getElementById ('log'); + node.value += msg + "\n"; + var len = node.value.length; + node.setSelectionRange (len, len); +} + MIM.debug_print = function (event, ic) { if (! MIM.debug) @@ -1978,8 +1998,8 @@ MIM.debug_print = function (event, ic) MIM.debug_nodes['status1'] = document.getElementById ('status1'); MIM.debug_nodes['keyseq0'] = document.getElementById ('keyseq0'); MIM.debug_nodes['keyseq1'] = document.getElementById ('keyseq1'); - MIM.debug_nodes['range0'] = document.getElementById ('range0'); - MIM.debug_nodes['range1'] = document.getElementById ('range1'); + MIM.debug_nodes['preedit0'] = document.getElementById ('preedit0'); + MIM.debug_nodes['preedit1'] = document.getElementById ('preedit1'); } var target = event.target; var code = event.keyCode; @@ -1989,7 +2009,10 @@ MIM.debug_print = function (event, ic) MIM.debug_nodes[event.type].innerHTML = "" + code + "/" + ch + " : " + key; index = (event.type == 'keydown' ? '0' : '1'); - MIM.debug_nodes['status' + index].innerHTML = ic.im.load_status; + if (ic) + MIM.debug_nodes['status' + index].innerHTML = ic.im.load_status; + else + MIM.debug_nodes['status' + index].innerHTML = 'no IM'; MIM.debug_nodes['keyseq' + index].innerHTML = ic.keys; MIM.debug_nodes['preedit' + index].innerHTML = ic.preedit; }; @@ -2040,15 +2063,17 @@ MIM.set_caret = function (target, ic) ic.spot = range[0]; } } -}; +}) (); -MIM.produce = function (target, ic) +MIM.update = function (target, ic, prevlen) { + var text = target.value; target.value = (text.substring (0, ic.spot) + ic.produced - + text.substring (ic.)); - ic.range[1] = ic.range[0] + insert.length; - MIM.set_caret (ic.target, ic.range[1]); + + ic.preedit + + text.substring (ic.spot + prevlen)); + ic.spot += ic.produced.length; + MIM.set_caret (target, ic); }; MIM.reset_ic = function (event) @@ -2067,7 +2092,7 @@ MIM.keydown = function (event) var ic = target.mim_ic; if (! ic || ic.im != MIM.current) { - ic = new MIM.IC (MIM.current_im); + ic = new MIM.IC (MIM.current); target.mim_ic = ic; MIM.add_event_listener (target, 'blur', MIM.reset_ic); } @@ -2087,7 +2112,8 @@ MIM.keypress = function (event) var i; try { - if (ic.im.loaded != MIM.LoadStatus.Loaded) + MIM.log (ic.im.name); + if (ic.im.load_status != MIM.LoadStatus.Loaded) return; if (! ic.key) ic.key = MIM.decode_key_event (event); @@ -2096,21 +2122,11 @@ MIM.keypress = function (event) ic.reset (); return; } - if (ic.Filter (ic.key)) - MIM.set_caret (target, ic); - else - { - if (ic.preedit.length > 0) - { - MIM.insert - - } - } - - - if (ic.im.status == 1) // Still loading. - return; - MIM.handle_keyseq (event, ic); + + var prevlen = ic.preedit.length; + MIM.log ("filtering " + ic.key); + var result = ic.Filter (ic.key); + MIM.update (target, ic, prevlen); } finally { MIM.debug_print (event, ic); } @@ -2133,8 +2149,8 @@ MIM.select_im = function (event) } document.getElementsByTagName ('body')[0].removeChild (target); target.target.focus (); - if (im && im != MIM.current_im) - MIM.current_im = MIM.load_sync (im); + if (im && im != MIM.current) + MIM.current = MIM.load_sync (im); }; MIM.destroy_menu = function (event) @@ -2167,7 +2183,7 @@ MIM.select_menu = function (event) option.appendChild (document.createTextNode (imname)); option.value = imname; sel.appendChild (option); - if (MIM.list[lang][name] == MIM.current_im) + if (MIM.list[lang][name] == MIM.current) sel.selectedIndex = idx; idx++; } @@ -2175,8 +2191,6 @@ MIM.select_menu = function (event) document.getElementsByTagName ('body')[0].appendChild (sel); }; - - MIM.test = function () { var im = MIM.im_list['t']['latn-post']; @@ -2198,3 +2212,20 @@ MIM.test = function () } } } + + +MIM.init = function () +{ + MIM.add_event_listener (window, 'keydown', MIM.keydown); + MIM.add_event_listener (window, 'keypress', MIM.keypress); + MIM.add_event_listener (window, 'mousedown', MIM.select_menu); + if (window.location == 'http://localhost/mim/index.html') + MIM.server = 'http://localhost/mim'; + MIM.current = MIM.im_list['t']['latn-post']; +}; + +MIM.init_debug = function () +{ + MIM.debug = true; + MIM.init (); +};