commit
ba015bb251
4 changed files with 76 additions and 23 deletions
|
|
@ -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 {
|
||||||
|
|
|
||||||
|
|
@ -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() {},
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -198,6 +198,7 @@ var TextInput = function(parentNode, host) {
|
||||||
var inputHandler = null;
|
var inputHandler = null;
|
||||||
this.setInputHandler = function(cb) {inputHandler = cb};
|
this.setInputHandler = function(cb) {inputHandler = cb};
|
||||||
this.getInputHandler = function() {return inputHandler};
|
this.getInputHandler = function() {return inputHandler};
|
||||||
|
var afterContextMenu = false;
|
||||||
|
|
||||||
var sendText = function(data) {
|
var sendText = function(data) {
|
||||||
if (inputHandler) {
|
if (inputHandler) {
|
||||||
|
|
@ -210,7 +211,7 @@ var TextInput = function(parentNode, host) {
|
||||||
host.onPaste(data);
|
host.onPaste(data);
|
||||||
pasted = false;
|
pasted = false;
|
||||||
} else if (data == PLACEHOLDER[0]) {
|
} else if (data == PLACEHOLDER[0]) {
|
||||||
if (Date.now() - lastCompositionTime > 100)
|
if (afterContextMenu)
|
||||||
host.execCommand("del", {source: "ace"});
|
host.execCommand("del", {source: "ace"});
|
||||||
} else {
|
} else {
|
||||||
if (data.substring(0, 2) == PLACEHOLDER)
|
if (data.substring(0, 2) == PLACEHOLDER)
|
||||||
|
|
@ -226,9 +227,11 @@ var TextInput = function(parentNode, host) {
|
||||||
if (data)
|
if (data)
|
||||||
host.onTextInput(data);
|
host.onTextInput(data);
|
||||||
}
|
}
|
||||||
|
if (afterContextMenu)
|
||||||
|
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);
|
||||||
|
|
@ -346,22 +349,61 @@ 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;
|
||||||
|
var timer = setTimeout(function() {
|
||||||
|
var str = text.value.replace(/\x01/g, "");
|
||||||
|
if (!inComposition && str == c.lastValue)
|
||||||
|
resetValue();
|
||||||
|
});
|
||||||
|
inputHandler = function compositionInputHandler(str) {
|
||||||
|
clearTimeout(timer);
|
||||||
|
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 lastCompositionTime = -1;
|
|
||||||
var onCompositionEnd = function(e) {
|
|
||||||
inCompostion = false;
|
|
||||||
host.onCompositionEnd();
|
|
||||||
lastCompositionTime = Date.now();
|
|
||||||
};
|
|
||||||
|
|
||||||
var syncComposition = lang.delayedCall(onCompositionUpdate, 50);
|
var syncComposition = lang.delayedCall(onCompositionUpdate, 50);
|
||||||
|
|
||||||
|
|
@ -378,6 +420,7 @@ var TextInput = function(parentNode, host) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.onContextMenu = function(e) {
|
this.onContextMenu = function(e) {
|
||||||
|
afterContextMenu = true;
|
||||||
if (!tempStyle)
|
if (!tempStyle)
|
||||||
tempStyle = text.style.cssText;
|
tempStyle = text.style.cssText;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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";
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue