From 84a2ceb28d28ab0dba94625b434c62db419f2c8b Mon Sep 17 00:00:00 2001 From: kyo_ago Date: Tue, 25 Jan 2011 22:47:33 +0900 Subject: [PATCH] fix multi byte input, rendering(Windows XP IE8, Firefox3.6, Chrome8) --- lib/ace/keyboard/textinput.js | 36 +++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/lib/ace/keyboard/textinput.js b/lib/ace/keyboard/textinput.js index 0cc2465b..11bbfe0d 100644 --- a/lib/ace/keyboard/textinput.js +++ b/lib/ace/keyboard/textinput.js @@ -38,6 +38,7 @@ define(function(require, exports, module) { var event = require("pilot/event"); +var useragent = require("pilot/useragent"); var TextInput = function(parentNode, host) { @@ -77,6 +78,7 @@ var TextInput = function(parentNode, host) { } var onTextInput = function(e) { + if (useragent.isIE && text.value.charCodeAt(0) > 128) return; setTimeout(function() { if (!inCompostion) sendText(); @@ -85,20 +87,25 @@ var TextInput = function(parentNode, host) { var onCompositionStart = function(e) { inCompostion = true; - sendText(); - text.value = ""; + if (!useragent.isIE) { + sendText(); + text.value = ""; + }; host.onCompositionStart(); - setTimeout(onCompositionUpdate, 0); + if (!useragent.isGecko) setTimeout(onCompositionUpdate, 0); }; var onCompositionUpdate = function() { + if (!inCompostion) return; host.onCompositionUpdate(text.value); }; var onCompositionEnd = function() { inCompostion = false; host.onCompositionEnd(); - onTextInput(); + setTimeout(function () { + sendText(); + }, 0); }; var onCopy = function() { @@ -119,6 +126,16 @@ var TextInput = function(parentNode, host) { event.addCommandKeyListener(text, host.onCommandKey.bind(host)); event.addListener(text, "keypress", onTextInput); + if (useragent.isIE) { + var keytable = { 13:1, 27:1 }; + event.addListener(text, "keyup", function (e) { + if (inCompostion && (!text.value || keytable[e.keyCode])) setTimeout(onCompositionEnd, 0); + if ((text.value.charCodeAt(0)|0) < 129) { + return; + }; + inCompostion ? onCompositionUpdate() : onCompositionStart(); + }); + }; event.addListener(text, "textInput", onTextInput); event.addListener(text, "paste", function(e) { // Some browsers support the event.clipboardData API. Use this to get @@ -133,13 +150,20 @@ var TextInput = function(parentNode, host) { onTextInput(); } }); - event.addListener(text, "propertychange", onTextInput); + if (!useragent.isIE) { + event.addListener(text, "propertychange", onTextInput); + }; event.addListener(text, "copy", onCopy); event.addListener(text, "cut", onCut); event.addListener(text, "compositionstart", onCompositionStart); - event.addListener(text, "compositionupdate", onCompositionUpdate); + if (useragent.isGecko) { + event.addListener(text, "text", onCompositionUpdate); + }; + if (useragent.isWebKit) { + event.addListener(text, "keyup", onCompositionUpdate); + }; event.addListener(text, "compositionend", onCompositionEnd); event.addListener(text, "blur", function() {