do not overlay editor text when ime is active

fixes #1112
This commit is contained in:
nightwing 2013-03-28 21:06:48 +04:00
commit b0a43790b4
4 changed files with 65 additions and 20 deletions

View file

@ -101,6 +101,8 @@
outline: none; outline: none;
overflow: hidden; overflow: hidden;
font: inherit; font: inherit;
padding: 0 1px;
margin: 0 -1px;
} }
.ace_text-input.ace_composition { .ace_text-input.ace_composition {
@ -108,9 +110,6 @@
color: #111; color: #111;
z-index: 1000; z-index: 1000;
opacity: 1; opacity: 1;
border: solid lightgray 1px;
margin: -1px;
padding: 0 1px;
} }
.ace_layer { .ace_layer {

View file

@ -417,6 +417,14 @@ var EditSession = function(text, mode) {
} }
}; };
/**
* starts a new group in undo history
**/
this.markUndoGroup = function() {
if (this.$syncInformUndoManager)
this.$syncInformUndoManager();
};
this.$defaultUndoManager = { this.$defaultUndoManager = {
undo: function() {}, undo: function() {},
redo: function() {}, redo: function() {},

View file

@ -59,7 +59,7 @@ var TextInput = function(parentNode, host) {
var cut = false; var cut = false;
var copied = false; var copied = false;
var pasted = false; var pasted = false;
var inCompostion = false; var inComposition = false;
var tempStyle = ''; var tempStyle = '';
var isSelectionEmpty = true; var isSelectionEmpty = true;
@ -87,14 +87,14 @@ var TextInput = function(parentNode, host) {
isFocused && resetSelection(isSelectionEmpty); isFocused && resetSelection(isSelectionEmpty);
}); });
var syncValue = lang.delayedCall(function() { var syncValue = lang.delayedCall(function() {
if (!inCompostion) { if (!inComposition) {
text.value = PLACEHOLDER; text.value = PLACEHOLDER;
isFocused && resetSelection(); isFocused && resetSelection();
} }
}); });
function resetSelection(isEmpty) { function resetSelection(isEmpty) {
if (inCompostion) if (inComposition)
return; return;
if (inputHandler) { if (inputHandler) {
selectionStart = 0; selectionStart = 0;
@ -110,7 +110,7 @@ var TextInput = function(parentNode, host) {
} }
function resetValue() { function resetValue() {
if (inCompostion) if (inComposition)
return; return;
text.value = PLACEHOLDER; text.value = PLACEHOLDER;
//http://code.google.com/p/chromium/issues/detail?id=76516 //http://code.google.com/p/chromium/issues/detail?id=76516
@ -156,7 +156,7 @@ var TextInput = function(parentNode, host) {
if (inPropertyChange) if (inPropertyChange)
return; return;
var data = text.value; var data = text.value;
if (inCompostion || !data || data == PLACEHOLDER) if (inComposition || !data || data == PLACEHOLDER)
return; return;
// can happen either after delete or during insert operation // can happen either after delete or during insert operation
if (e && data == PLACEHOLDER[0]) if (e && data == PLACEHOLDER[0])
@ -173,12 +173,12 @@ var TextInput = function(parentNode, host) {
var keytable = { 13:1, 27:1 }; var keytable = { 13:1, 27:1 };
event.addListener(text, "keyup", function (e) { event.addListener(text, "keyup", function (e) {
if (inCompostion && (!text.value || keytable[e.keyCode])) if (inComposition && (!text.value || keytable[e.keyCode]))
setTimeout(onCompositionEnd, 0); setTimeout(onCompositionEnd, 0);
if ((text.value.charCodeAt(0)||0) < 129) { if ((text.value.charCodeAt(0)||0) < 129) {
return; return;
} }
inCompostion ? onCompositionUpdate() : onCompositionStart(); inComposition ? onCompositionUpdate() : onCompositionStart();
}); });
} }
@ -231,7 +231,7 @@ var TextInput = function(parentNode, host) {
afterContextMenu = false; afterContextMenu = false;
}; };
var onInput = function(e) { var onInput = function(e) {
if (inCompostion) if (inComposition)
return; return;
var data = text.value; var data = text.value;
sendText(data); sendText(data);
@ -349,20 +349,55 @@ var TextInput = function(parentNode, host) {
// COMPOSITION // COMPOSITION
var onCompositionStart = function(e) { var onCompositionStart = function(e) {
inCompostion = true; inComposition = {};
host.onCompositionStart(); host.onCompositionStart();
setTimeout(onCompositionUpdate, 0); setTimeout(onCompositionUpdate, 0);
host.on("mousedown", onCompositionEnd);
if (!host.selection.isEmpty()) {
host.insert("");
host.session.markUndoGroup();
host.selection.clearSelection();
}
host.session.markUndoGroup();
}; };
var onCompositionUpdate = function() { var onCompositionUpdate = function() {
if (!inCompostion) return; if (!inComposition) return;
host.onCompositionUpdate(text.value); host.onCompositionUpdate(text.value);
if (inComposition.lastValue)
host.undo();
inComposition.lastValue = text.value.replace(/\x01/g, "")
if (inComposition.lastValue) {
var r = host.selection.getRange();
host.insert(inComposition.lastValue);
host.session.markUndoGroup();
inComposition.range = host.selection.getRange();
host.selection.setRange(r);
host.selection.clearSelection();
}
};
var onCompositionEnd = function(e) {
var c = inComposition;
inComposition = false;
inputHandler = function compositionInputHandler(str) {
str = str.replace(/\x01/g, "");
if (str == c.lastValue)
return "";
if (!str) {
if (c.lastValue)
host.undo();
}
return str;
}
host.onCompositionEnd();
host.removeListener("mousedown", onCompositionEnd);
if (e.type == "compositionend") {
host.selection.setRange(c.range);
}
}; };
var onCompositionEnd = function(e) {
inCompostion = false;
host.onCompositionEnd();
};
var syncComposition = lang.delayedCall(onCompositionUpdate, 50); var syncComposition = lang.delayedCall(onCompositionUpdate, 50);

View file

@ -538,13 +538,16 @@ var VirtualRenderer = function(container, theme) {
var posLeft = this.$cursorLayer.$pixelPos.left; var posLeft = this.$cursorLayer.$pixelPos.left;
posTop -= config.offset; posTop -= config.offset;
if (posTop < 0 || posTop > config.height - this.lineHeight) var h = this.lineHeight;
if (posTop < 0 || posTop > config.height - h)
return; return;
var w = this.characterWidth; var w = this.characterWidth;
if (this.$composition) { if (this.$composition) {
var val = this.textarea.value.replace(/^\x01+/, ""); var val = this.textarea.value.replace(/^\x01+/, "");
w *= this.session.$getStringScreenWidth(val)[0]; w *= this.session.$getStringScreenWidth(val)[0];
h += 2;
posTop -= 1;
} }
posLeft -= this.scrollLeft; posLeft -= this.scrollLeft;
if (posLeft > this.$size.scrollerWidth - w) if (posLeft > this.$size.scrollerWidth - w)
@ -552,10 +555,10 @@ var VirtualRenderer = function(container, theme) {
posLeft -= this.scrollBar.width; posLeft -= this.scrollBar.width;
this.textarea.style.height = this.lineHeight + "px"; this.textarea.style.height = h + "px";
this.textarea.style.width = w + "px"; this.textarea.style.width = w + "px";
this.textarea.style.right = Math.max(0, this.$size.scrollerWidth - posLeft - w) + "px"; this.textarea.style.right = Math.max(0, this.$size.scrollerWidth - posLeft - w) + "px";
this.textarea.style.bottom = Math.max(0, this.$size.height - posTop - this.lineHeight) + "px"; this.textarea.style.bottom = Math.max(0, this.$size.height - posTop - h) + "px";
}; };
/** /**