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 += ' ';
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 ();
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)
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;
};
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;
{
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);
}
{
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
}
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)
{
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
{
if (! this.initial_state)
this.initial_state = state;
this.state_list[sname] = state;
- Xex.Log ('include state ' + sname);
}
}
else if (node.nodeName == 'state')
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:');
}
else
{
- Xex.Log ('no submap');
+ Xex.Log (' without submap');
var current_state = this.state;
var map = this.keymap;
proto = {
reset: function ()
{
- Xex.Log ('reseting ' + this.im.lang + '-' + this.im.name);
this.cursor_pos = 0;
this.candidate_show = false;
this.prev_state = null;
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;
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;
}
},
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;
}
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);
}
}
}
}
+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;
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);
}
}
};
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'];
};
}) ();