{
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)
}
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;
}
{
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)
{
= 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)
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;
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;
};
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)
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);
}
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);
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);
}
}
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)
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++;
}
document.getElementsByTagName ('body')[0].appendChild (sel);
};
-
-
MIM.test = function ()
{
var im = MIM.im_list['t']['latn-post'];
}
}
}
+
+
+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 ();
+};