restore selection only if something is selected
This commit is contained in:
parent
0e87da74b2
commit
0cd2faecc5
2 changed files with 26 additions and 25 deletions
|
|
@ -34,6 +34,7 @@ define(function(require, exports, module) {
|
||||||
var event = require("../lib/event");
|
var event = require("../lib/event");
|
||||||
var useragent = require("../lib/useragent");
|
var useragent = require("../lib/useragent");
|
||||||
var dom = require("../lib/dom");
|
var dom = require("../lib/dom");
|
||||||
|
var lang = require("../lib/lang");
|
||||||
|
|
||||||
var TextInput = function(parentNode, host) {
|
var TextInput = function(parentNode, host) {
|
||||||
var text = dom.createElement("textarea");
|
var text = dom.createElement("textarea");
|
||||||
|
|
@ -61,9 +62,17 @@ var TextInput = function(parentNode, host) {
|
||||||
var copied = false;
|
var copied = false;
|
||||||
var pasted = false;
|
var pasted = false;
|
||||||
var inCompostion = false;
|
var inCompostion = false;
|
||||||
var resetTimeout = null;
|
|
||||||
var tempStyle = '';
|
var tempStyle = '';
|
||||||
|
var isSelectionEmpty = true;
|
||||||
|
var syncSelection = lang.delayedCall(function() {
|
||||||
|
resetSelection(isSelectionEmpty);
|
||||||
|
});
|
||||||
|
var syncValue = lang.delayedCall(function() {
|
||||||
|
if (!inCompostion) {
|
||||||
|
text.value = PLACEHOLDER;
|
||||||
|
resetSelection();
|
||||||
|
}
|
||||||
|
});
|
||||||
resetValue();
|
resetValue();
|
||||||
if (isFocused())
|
if (isFocused())
|
||||||
host.onFocus();
|
host.onFocus();
|
||||||
|
|
@ -90,7 +99,7 @@ var TextInput = function(parentNode, host) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (useragent.isOldIE) {
|
if (useragent.isOldIE) {
|
||||||
var propchangeTimeout;
|
var syncProperty = lang.delayedCall(onPropertyChange);
|
||||||
var propertyChangeCounter = 0;
|
var propertyChangeCounter = 0;
|
||||||
var onPropertyChange = function(e){
|
var onPropertyChange = function(e){
|
||||||
if (propertyChangeCounter)
|
if (propertyChangeCounter)
|
||||||
|
|
@ -99,20 +108,13 @@ var TextInput = function(parentNode, host) {
|
||||||
if (inCompostion || !data || data == PLACEHOLDER)
|
if (inCompostion || !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])
|
||||||
if (!propchangeTimeout) {
|
return syncProperty.schedule();
|
||||||
propchangeTimeout = setTimeout(function() {
|
|
||||||
onPropertyChange();
|
|
||||||
propchangeTimeout = null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sendText(data);
|
sendText(data);
|
||||||
propertyChangeCounter++
|
propertyChangeCounter++;
|
||||||
resetValue();
|
resetValue();
|
||||||
propertyChangeCounter--
|
propertyChangeCounter--;
|
||||||
}
|
}
|
||||||
event.addListener(text, "propertychange", onPropertyChange);
|
event.addListener(text, "propertychange", onPropertyChange);
|
||||||
|
|
||||||
|
|
@ -132,16 +134,8 @@ var TextInput = function(parentNode, host) {
|
||||||
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
|
||||||
if (!resetTimeout) {
|
if (useragent.isWebKit)
|
||||||
resetTimeout = setTimeout(function(){
|
syncValue.schedule();
|
||||||
resetTimeout = null;
|
|
||||||
if (inCompostion)
|
|
||||||
return;
|
|
||||||
if (useragent.isWebKit)
|
|
||||||
text.value = PLACEHOLDER;
|
|
||||||
resetSelection();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function resetSelection(isEmpty) {
|
function resetSelection(isEmpty) {
|
||||||
|
|
@ -407,6 +401,13 @@ var TextInput = function(parentNode, host) {
|
||||||
onContextMenuClose();
|
onContextMenuClose();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
host.addEventListener('changeSelection', function(){
|
||||||
|
if (host.selection.isEmpty() != isSelectionEmpty) {
|
||||||
|
isSelectionEmpty = !isSelectionEmpty;
|
||||||
|
syncSelection.schedule();
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.TextInput = TextInput;
|
exports.TextInput = TextInput;
|
||||||
|
|
|
||||||
|
|
@ -179,7 +179,7 @@ exports.delayedCall = function(fcn, defaultTimeout) {
|
||||||
timer = setTimeout(callback, timeout || defaultTimeout);
|
timer = setTimeout(callback, timeout || defaultTimeout);
|
||||||
};
|
};
|
||||||
|
|
||||||
_self.delay = delayed;
|
_self.delay = _self;
|
||||||
_self.schedule = function(timeout) {
|
_self.schedule = function(timeout) {
|
||||||
if (timer == null)
|
if (timer == null)
|
||||||
timer = setTimeout(callback, timeout || 0);
|
timer = setTimeout(callback, timeout || 0);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue