cleanup
This commit is contained in:
parent
c9b8159382
commit
125629ce17
1 changed files with 36 additions and 42 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* Copyright (c) 2010, Ajax.org B.V.
|
* Copyright (c) 2010, Ajax.org B.V.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* * Redistributions of source code must retain the above copyright
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
* * Neither the name of Ajax.org B.V. nor the
|
* * Neither the name of Ajax.org B.V. nor the
|
||||||
* names of its contributors may be used to endorse or promote products
|
* names of its contributors may be used to endorse or promote products
|
||||||
* derived from this software without specific prior written permission.
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
|
@ -40,16 +40,13 @@ var TextInput = function(parentNode, host) {
|
||||||
var text = dom.createElement("textarea");
|
var text = dom.createElement("textarea");
|
||||||
text.className = "ace_text-input";
|
text.className = "ace_text-input";
|
||||||
/*/ debug
|
/*/ debug
|
||||||
text.style.opacity = 1
|
text.style.cssText = "opacity:1;background:rgba(0, 250, 0, 0.3);outline:rgba(0, 250, 0, 0.8) solid 1px;outline-offset:3px;width:5em;z-index:500";
|
||||||
text.style.background = "rgba(0, 250, 0, 0.3)"
|
|
||||||
text.style.outline = "rgba(0, 250, 0, 0.8) solid 1px"
|
|
||||||
text.style.outlineOffset = "3px"
|
|
||||||
/**/
|
/**/
|
||||||
if (useragent.isTouchPad)
|
if (useragent.isTouchPad)
|
||||||
text.setAttribute("x-palm-disable-auto-cap", true);
|
text.setAttribute("x-palm-disable-auto-cap", true);
|
||||||
|
|
||||||
text.wrap = "off";
|
text.wrap = "off";
|
||||||
text.autocorrect = "off";
|
text.autocorrect = "off";
|
||||||
text.autocapitalize = "off";
|
text.autocapitalize = "off";
|
||||||
text.spellcheck = false;
|
text.spellcheck = false;
|
||||||
|
|
||||||
|
|
@ -58,7 +55,7 @@ var TextInput = function(parentNode, host) {
|
||||||
|
|
||||||
var PLACEHOLDER = "\x01\x01";
|
var PLACEHOLDER = "\x01\x01";
|
||||||
|
|
||||||
var cut = false
|
var cut = false;
|
||||||
var copied = false;
|
var copied = false;
|
||||||
var pasted = false;
|
var pasted = false;
|
||||||
var inCompostion = false;
|
var inCompostion = false;
|
||||||
|
|
@ -76,12 +73,8 @@ var TextInput = function(parentNode, host) {
|
||||||
host.onFocus();
|
host.onFocus();
|
||||||
resetSelection();
|
resetSelection();
|
||||||
});
|
});
|
||||||
this.focus = function() {
|
this.focus = function() { text.focus(); };
|
||||||
text.focus();
|
this.blur = function() { text.blur(); };
|
||||||
};
|
|
||||||
this.blur = function() {
|
|
||||||
text.blur();
|
|
||||||
};
|
|
||||||
this.isFocused = function() {
|
this.isFocused = function() {
|
||||||
return isFocused;
|
return isFocused;
|
||||||
};
|
};
|
||||||
|
|
@ -106,7 +99,7 @@ var TextInput = function(parentNode, host) {
|
||||||
try {
|
try {
|
||||||
text.setSelectionRange(selectionStart, selectionEnd);
|
text.setSelectionRange(selectionStart, selectionEnd);
|
||||||
} catch(e){}
|
} catch(e){}
|
||||||
};
|
}
|
||||||
|
|
||||||
function resetValue() {
|
function resetValue() {
|
||||||
if (inCompostion)
|
if (inCompostion)
|
||||||
|
|
@ -115,7 +108,7 @@ var TextInput = function(parentNode, host) {
|
||||||
//http://code.google.com/p/chromium/issues/detail?id=76516
|
//http://code.google.com/p/chromium/issues/detail?id=76516
|
||||||
if (useragent.isWebKit)
|
if (useragent.isWebKit)
|
||||||
syncValue.schedule();
|
syncValue.schedule();
|
||||||
};
|
}
|
||||||
|
|
||||||
useragent.isWebKit || host.addEventListener('changeSelection', function() {
|
useragent.isWebKit || host.addEventListener('changeSelection', function() {
|
||||||
if (host.selection.isEmpty() != isSelectionEmpty) {
|
if (host.selection.isEmpty() != isSelectionEmpty) {
|
||||||
|
|
@ -124,7 +117,6 @@ var TextInput = function(parentNode, host) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
resetValue();
|
resetValue();
|
||||||
if (isFocused)
|
if (isFocused)
|
||||||
host.onFocus();
|
host.onFocus();
|
||||||
|
|
@ -132,7 +124,7 @@ var TextInput = function(parentNode, host) {
|
||||||
|
|
||||||
var isAllSelected = function(text) {
|
var isAllSelected = function(text) {
|
||||||
return text.selectionStart === 0 && text.selectionEnd === text.value.length;
|
return text.selectionStart === 0 && text.selectionEnd === text.value.length;
|
||||||
}
|
};
|
||||||
// IE8 does not support setSelectionRange
|
// IE8 does not support setSelectionRange
|
||||||
if (!text.setSelectionRange && text.createTextRange) {
|
if (!text.setSelectionRange && text.createTextRange) {
|
||||||
text.setSelectionRange = function(selectionStart, selectionEnd) {
|
text.setSelectionRange = function(selectionStart, selectionEnd) {
|
||||||
|
|
@ -151,8 +143,6 @@ var TextInput = function(parentNode, host) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (useragent.isOldIE) {
|
if (useragent.isOldIE) {
|
||||||
var syncProperty = lang.delayedCall(onPropertyChange);
|
|
||||||
var propertyChangeCounter = 0;
|
|
||||||
var onPropertyChange = function(e){
|
var onPropertyChange = function(e){
|
||||||
if (propertyChangeCounter)
|
if (propertyChangeCounter)
|
||||||
return;
|
return;
|
||||||
|
|
@ -167,7 +157,9 @@ var TextInput = function(parentNode, host) {
|
||||||
propertyChangeCounter++;
|
propertyChangeCounter++;
|
||||||
resetValue();
|
resetValue();
|
||||||
propertyChangeCounter--;
|
propertyChangeCounter--;
|
||||||
}
|
};
|
||||||
|
var syncProperty = lang.delayedCall(onPropertyChange);
|
||||||
|
var propertyChangeCounter = 0;
|
||||||
event.addListener(text, "propertychange", onPropertyChange);
|
event.addListener(text, "propertychange", onPropertyChange);
|
||||||
|
|
||||||
var keytable = { 13:1, 27:1 };
|
var keytable = { 13:1, 27:1 };
|
||||||
|
|
@ -228,22 +220,6 @@ var TextInput = function(parentNode, host) {
|
||||||
sendText(data);
|
sendText(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
var onCompositionStart = function(e) {
|
|
||||||
inCompostion = true;
|
|
||||||
host.onCompositionStart();
|
|
||||||
setTimeout(onCompositionUpdate, 0);
|
|
||||||
};
|
|
||||||
|
|
||||||
var onCompositionUpdate = function() {
|
|
||||||
if (!inCompostion) return;
|
|
||||||
host.onCompositionUpdate(text.value);
|
|
||||||
};
|
|
||||||
|
|
||||||
var onCompositionEnd = function(e) {
|
|
||||||
inCompostion = false;
|
|
||||||
host.onCompositionEnd();
|
|
||||||
};
|
|
||||||
|
|
||||||
var onCut = function(e) {
|
var onCut = function(e) {
|
||||||
var data = host.getCopyText();
|
var data = host.getCopyText();
|
||||||
if (!data) {
|
if (!data) {
|
||||||
|
|
@ -354,10 +330,27 @@ var TextInput = function(parentNode, host) {
|
||||||
|
|
||||||
|
|
||||||
// COMPOSITION
|
// COMPOSITION
|
||||||
|
var onCompositionStart = function(e) {
|
||||||
|
inCompostion = true;
|
||||||
|
host.onCompositionStart();
|
||||||
|
setTimeout(onCompositionUpdate, 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
var onCompositionUpdate = function() {
|
||||||
|
if (!inCompostion) return;
|
||||||
|
host.onCompositionUpdate(text.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
var onCompositionEnd = function(e) {
|
||||||
|
inCompostion = false;
|
||||||
|
host.onCompositionEnd();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
event.addListener(text, "compositionstart", onCompositionStart);
|
event.addListener(text, "compositionstart", onCompositionStart);
|
||||||
if (useragent.isGecko)
|
if (useragent.isGecko)
|
||||||
event.addListener(text, "text", onCompositionUpdate);
|
event.addListener(text, "text", onCompositionUpdate);
|
||||||
if (useragent.isWebKit)
|
else
|
||||||
event.addListener(text, "keyup", onCompositionUpdate);
|
event.addListener(text, "keyup", onCompositionUpdate);
|
||||||
event.addListener(text, "compositionend", onCompositionEnd);
|
event.addListener(text, "compositionend", onCompositionEnd);
|
||||||
|
|
||||||
|
|
@ -370,8 +363,8 @@ var TextInput = function(parentNode, host) {
|
||||||
if (!tempStyle)
|
if (!tempStyle)
|
||||||
tempStyle = text.style.cssText;
|
tempStyle = text.style.cssText;
|
||||||
|
|
||||||
text.style.cssText = "z-index:100000;" +
|
text.style.cssText = "z-index:100000;" + (useragent.isIE ? "opacity:0.1;" : "");
|
||||||
(useragent.isIE ? "opacity:0.1;" : "")// + "background:rgba(250, 0, 0, 0.3); opacity:1;"
|
// text.style.cssText += "background:rgba(250, 0, 0, 0.3); opacity:1;";
|
||||||
|
|
||||||
resetSelection(host.selection.isEmpty());
|
resetSelection(host.selection.isEmpty());
|
||||||
host._emit("nativecontextmenu", {target: editor});
|
host._emit("nativecontextmenu", {target: editor});
|
||||||
|
|
@ -393,7 +386,8 @@ var TextInput = function(parentNode, host) {
|
||||||
event.capture(host.container, move, onContextMenuClose);
|
event.capture(host.container, move, onContextMenuClose);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.onContextMenuClose = function() {
|
this.onContextMenuClose = onContextMenuClose;
|
||||||
|
function onContextMenuClose() {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
if (tempStyle) {
|
if (tempStyle) {
|
||||||
text.style.cssText = tempStyle;
|
text.style.cssText = tempStyle;
|
||||||
|
|
@ -404,7 +398,7 @@ var TextInput = function(parentNode, host) {
|
||||||
host.renderer.$moveTextAreaToCursor();
|
host.renderer.$moveTextAreaToCursor();
|
||||||
}
|
}
|
||||||
}, 0);
|
}, 0);
|
||||||
};
|
}
|
||||||
|
|
||||||
// firefox fires contextmenu event after opening it
|
// firefox fires contextmenu event after opening it
|
||||||
if (!useragent.isGecko) {
|
if (!useragent.isGecko) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue