better compositionUpdate on chrome
This commit is contained in:
parent
0b4c56c5a7
commit
2ace399a8a
1 changed files with 12 additions and 4 deletions
|
|
@ -51,7 +51,7 @@ var TextInput = function(parentNode, host) {
|
|||
text.autocapitalize = "off";
|
||||
text.spellcheck = false;
|
||||
|
||||
text.style.bottom = "2000em";
|
||||
text.style.opacity = "0";
|
||||
parentNode.insertBefore(text, parentNode.firstChild);
|
||||
|
||||
var PLACEHOLDER = "\x01\x01";
|
||||
|
|
@ -372,10 +372,13 @@ var TextInput = function(parentNode, host) {
|
|||
var onCompositionUpdate = function() {
|
||||
// console.log("onCompositionUpdate", inComposition && JSON.stringify(text.value))
|
||||
if (!inComposition) return;
|
||||
host.onCompositionUpdate(text.value);
|
||||
var val = text.value.replace(/\x01/g, "");
|
||||
if (inComposition.lastValue === val) return;
|
||||
|
||||
host.onCompositionUpdate(val);
|
||||
if (inComposition.lastValue)
|
||||
host.undo();
|
||||
inComposition.lastValue = text.value.replace(/\x01/g, "")
|
||||
inComposition.lastValue = val;
|
||||
if (inComposition.lastValue) {
|
||||
var r = host.selection.getRange();
|
||||
host.insert(inComposition.lastValue);
|
||||
|
|
@ -424,7 +427,12 @@ var TextInput = function(parentNode, host) {
|
|||
var syncComposition = lang.delayedCall(onCompositionUpdate, 50);
|
||||
|
||||
event.addListener(text, "compositionstart", onCompositionStart);
|
||||
event.addListener(text, useragent.isGecko ? "text" : "keyup", function(){syncComposition.schedule()});
|
||||
if (useragent.isGecko) {
|
||||
event.addListener(text, "text", function(){syncComposition.schedule()});
|
||||
} else {
|
||||
event.addListener(text, "keyup", function(){syncComposition.schedule()});
|
||||
event.addListener(text, "keydown", function(){syncComposition.schedule()});
|
||||
}
|
||||
event.addListener(text, "compositionend", onCompositionEnd);
|
||||
|
||||
this.getElement = function() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue