From a4d2683fd40c0a21a1dad228da5f09e78d659196 Mon Sep 17 00:00:00 2001 From: handa Date: Tue, 9 Mar 2010 13:12:09 +0000 Subject: [PATCH] *** empty log message *** --- xex.js | 113 ++++++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 71 insertions(+), 42 deletions(-) diff --git a/xex.js b/xex.js index f719855..542e94d 100644 --- a/xex.js +++ b/xex.js @@ -2,15 +2,19 @@ var Xex = { LogNode: null, - Log: function (arg, indent) + LogSuspended: '', + Log: function (arg, indent, suspend) { if (! Xex.LogNode) return; if (! arg) Xex.LogNode.value = ''; + else if (suspend) + Xex.LogSuspended += arg; else { - var str = ''; + var str = Xex.LogSuspended; + Xex.LogSuspended = ''; if (indent != undefined) for (var i = 0; i <= indent; i++) str += ' '; @@ -249,7 +253,11 @@ Xex.Domain = function (name, parent, context) for (elt in parent.functions) this.functions[elt] = parent.functions[elt]; for (elt in parent.variables) - this.variables[elt] = parent.variables[elt]; + { + var vari = parent.variables[elt]; + this.variables[elt] = new Xex.Variable (this, vari.name, vari.desc, + vari.val, vari.range); + } } this.call_stack = new Array (); @@ -624,10 +632,9 @@ Xex.Varref = function (vname) proto.Clone = function () { return new Xex.Varref (this.val); } proto.Eval = function (domain) { - if (! this.vari || this.vari.domain != domain) - this.vari = domain.GetVarCreate (this.val); - Xex.Log (this.ToString () + '=>' + this.vari.val, domain.depth); - return this.vari.val; + var vari = domain.GetVarCreate (this.val); + Xex.Log (this.ToString () + '=>' + vari.val, domain.depth); + return vari.val; } proto.Parser = function (domain, node) @@ -645,10 +652,10 @@ Xex.Varref = function (vname) var null_args = new Array (); -Xex.Funcall = function (func, vari, args) +Xex.Funcall = function (func, vname, args) { this.func = func; - this.vari = vari; + this.vname = vname; this.args = args || null_args; }; @@ -663,18 +670,17 @@ Xex.Funcall = function (func, vari, args) if (fname == 'funcall') fname = node.attributes['fname'].nodeValue; var func = domain.GetFunc (fname); - var vari; + var vname; attr = node.attributes['vname']; - vari = attr != undefined ? domain.GetVarCreate (attr.nodeValue) : null; + vname = attr != undefined ? attr.nodeValue : null; var args = Xex.Term.Parse (domain, node.firstElement (), null); - return new Xex.Funcall (func, vari, args); + return new Xex.Funcall (func, vname, args); } proto.New = function (domain, fname, vname, args) { var func = domain.GetFunc (fname); - var vari = vname ? domain.GetVarCreate (vname) : null; - var funcall = new Xex.Funcall (func, vari, args); + var funcall = new Xex.Funcall (func, vname, args); if (func instanceof Xex.Macro) funcall = funcall.Eval (domain); return funcall; @@ -684,10 +690,13 @@ Xex.Funcall = function (func, vari, args) { if (! (this.func instanceof Xex.Subrountine)) Xex.Log (this, domain.depth); + var vari; + if (this.vname) + vari = domain.GetVarCreate (this.vname); domain.depth++; var result; try { - result = this.func.Call (domain, this.vari, this.args); + result = this.func.Call (domain, vari, this.args); } finally { Xex.Log (this + ' => ' + result, --domain.depth); } @@ -2122,6 +2131,7 @@ MIM.im_domain.DefType (MIM.State.prototype); { var ic = domain.context; var n = args.length == 0 ? -2 : args[0].val; + Xex.Log ('undo with arg ' + args[0]); if (n < 0) ic.keys.val.splice (ic.keys.val.length + n, -n); else @@ -2137,10 +2147,10 @@ MIM.im_domain.DefType (MIM.State.prototype); } function Funhandle (domain, vari, args) - { - domain.context.commit (); - return Xex.Fthrow (domain, vari, Xex.CatchTag._mimtag); - } + { + domain.context.commit (); + return Xex.Fthrow (domain, vari, Xex.CatchTag._mimtag); + } function Fshift (domain, vari, args) { @@ -2292,10 +2302,7 @@ MIM.im_domain.DefType (MIM.State.prototype); continue; } for (var mname in im.map_list) - { - this.map_list[mname] = im.map_list[mname]; - Xex.Log ('include map ' + mname); - } + this.map_list[mname] = im.map_list[mname]; } else { @@ -2320,7 +2327,6 @@ MIM.im_domain.DefType (MIM.State.prototype); if (! this.initial_state) this.initial_state = state; this.state_list[sname] = state; - Xex.Log ('include state ' + sname); } } else if (node.nodeName == 'state') @@ -2484,14 +2490,13 @@ MIM.im_domain.DefType (MIM.State.prototype); var sub = out.map; Xex.Log ('handling ' + this.keys.val[this.key_head] - + ' in ' + this.state.name + ':' + this.keymap.name); + + ' in ' + this.state.name + ':' + this.keymap.name, 0, true); this.key_head = out.index; if (sub != this.keymap) { - + Xex.Log (' with submap'); restore_state.call (this); this.keymap = sub; - Xex.Log ('submap found'); if (this.keymap.map_actions) { Xex.Log ('taking map actions:'); @@ -2522,7 +2527,7 @@ MIM.im_domain.DefType (MIM.State.prototype); } else { - Xex.Log ('no submap'); + Xex.Log (' without submap'); var current_state = this.state; var map = this.keymap; @@ -2554,7 +2559,6 @@ MIM.im_domain.DefType (MIM.State.prototype); proto = { reset: function () { - Xex.Log ('reseting ' + this.im.lang + '-' + this.im.name); this.cursor_pos = 0; this.candidate_show = false; this.prev_state = null; @@ -2564,6 +2568,7 @@ MIM.im_domain.DefType (MIM.State.prototype); this.state_var_values = {}; this.state_pos = 0; this.key_head = 0; + this.commit_key_head = 0; this.key_unhandled = false; this.unhandled_key = null; this.changed = MIM.ChangedStatus.None; @@ -2780,6 +2785,9 @@ MIM.im_domain.DefType (MIM.State.prototype); this.candidate_table.clear (); this.produced += this.preedit; this.preedit_replace.call (this, 0, this.preedit.length, '', null); + this.preedit_saved = ''; + this.state_pos = 0; + this.commit_key_head = this.key_head; } }, @@ -2841,6 +2849,10 @@ MIM.im_domain.DefType (MIM.State.prototype); this.unhandled_key = this.keys.val[this.key_head]; this.keys.val.splice (this.key_head, this.key_head + 1); } + if (this.state_key_head > 0) + this.state_key_head--; + if (this.commit_key_head > 0) + this.commit_key_head--; this.key_unhandled = true; break; } @@ -2851,14 +2863,23 @@ MIM.im_domain.DefType (MIM.State.prototype); break; } } + if (this.keymap == this.initial_state.keymap) + this.commit (); + + if (this.commit_key_head > 0) + { + this.keys.val.splice (0, this.commit_key_head); + this.key_head -= this.commit_key_head; + this.state_key_head -= this.commit_key_head; + this.commit_key_head = 0; + } if (this.key_unhandled) { this.keys.val.length = 0; this.key_head = this.state_key_head = this.commit_key_head = 0; } return (! this.key_unhandled - && this.produced.length == 0 - && this.preedit.length == 0); + && this.produced.length == 0); } } @@ -3130,6 +3151,15 @@ MIM.focus_in = function (event) } } +MIM.cancel_ignore_focus = function () +{ + if (MIM.focus_ignore_target) + { + MIM.focus_ignore_target.mim_ignore_focus_in = false; + MIM.focus_ignore_target.mim_ignore_focus_out = false; + } +} + MIM.focus_out = function (event) { var target = event.target; @@ -3146,16 +3176,15 @@ MIM.focus_out = function (event) else { Xex.Log ('focus_out in ' + target.tagName); - try { - if (! MIM.get_range (target, ic)) - ic.reset (); - ic.Filter (MIM.Key.FocusOut); - // Ignore further focus-out caused by setSelectionRange (). - target.mim_ignore_focus_in = true; - target.mim_ignore_focus_out = true; - MIM.update (target, ic); - } - catch (e) { Xex.Log ('Error:' + e); throw (e); } + if (! MIM.get_range (target, ic)) + ic.reset (); + ic.Filter (MIM.Key.FocusOut); + // Ignore further focus-out caused by setSelectionRange (). + target.mim_ignore_focus_in = true; + target.mim_ignore_focus_out = true; + MIM.focus_ignore_target = target; + MIM.update (target, ic); + setTimeout (MIM.cancel_ignore_focus, 100); } } }; @@ -3498,7 +3527,7 @@ MIM.keypress = function (event) MIM.add_event_listener (window, 'mousedown', create_menu); if (window.location == 'http://localhost/mim/index.html') MIM.server = 'http://localhost/mim'; - MIM.current = MIM.imlist['vi']['telex']; + MIM.current = MIM.imlist['zh']['tonepy']; }; }) (); -- 1.7.10.4