diff --git a/lib/ace/keyboard/textinput.js b/lib/ace/keyboard/textinput.js index f20740b7..77412920 100644 --- a/lib/ace/keyboard/textinput.js +++ b/lib/ace/keyboard/textinput.js @@ -34,6 +34,7 @@ define(function(require, exports, module) { var event = require("../lib/event"); var useragent = require("../lib/useragent"); var dom = require("../lib/dom"); +var lang = require("../lib/lang"); var TextInput = function(parentNode, host) { var text = dom.createElement("textarea"); @@ -61,9 +62,17 @@ var TextInput = function(parentNode, host) { var copied = false; var pasted = false; var inCompostion = false; - var resetTimeout = null; var tempStyle = ''; - + var isSelectionEmpty = true; + var syncSelection = lang.delayedCall(function() { + resetSelection(isSelectionEmpty); + }); + var syncValue = lang.delayedCall(function() { + if (!inCompostion) { + text.value = PLACEHOLDER; + resetSelection(); + } + }); resetValue(); if (isFocused()) host.onFocus(); @@ -90,7 +99,7 @@ var TextInput = function(parentNode, host) { } } if (useragent.isOldIE) { - var propchangeTimeout; + var syncProperty = lang.delayedCall(onPropertyChange); var propertyChangeCounter = 0; var onPropertyChange = function(e){ if (propertyChangeCounter) @@ -99,20 +108,13 @@ var TextInput = function(parentNode, host) { if (inCompostion || !data || data == PLACEHOLDER) return; // can happen either after delete or during insert operation - if (e && data == PLACEHOLDER[0]) { - if (!propchangeTimeout) { - propchangeTimeout = setTimeout(function() { - onPropertyChange(); - propchangeTimeout = null; - }); - } - return; - } + if (e && data == PLACEHOLDER[0]) + return syncProperty.schedule(); sendText(data); - propertyChangeCounter++ + propertyChangeCounter++; resetValue(); - propertyChangeCounter-- + propertyChangeCounter--; } event.addListener(text, "propertychange", onPropertyChange); @@ -132,16 +134,8 @@ var TextInput = function(parentNode, host) { return; text.value = PLACEHOLDER; //http://code.google.com/p/chromium/issues/detail?id=76516 - if (!resetTimeout) { - resetTimeout = setTimeout(function(){ - resetTimeout = null; - if (inCompostion) - return; - if (useragent.isWebKit) - text.value = PLACEHOLDER; - resetSelection(); - }); - } + if (useragent.isWebKit) + syncValue.schedule(); }; function resetSelection(isEmpty) { @@ -407,6 +401,13 @@ var TextInput = function(parentNode, host) { onContextMenuClose(); }); } + + host.addEventListener('changeSelection', function(){ + if (host.selection.isEmpty() != isSelectionEmpty) { + isSelectionEmpty = !isSelectionEmpty; + syncSelection.schedule(); + } + }); }; exports.TextInput = TextInput; diff --git a/lib/ace/lib/lang.js b/lib/ace/lib/lang.js index 6ea59761..4f81c842 100644 --- a/lib/ace/lib/lang.js +++ b/lib/ace/lib/lang.js @@ -179,7 +179,7 @@ exports.delayedCall = function(fcn, defaultTimeout) { timer = setTimeout(callback, timeout || defaultTimeout); }; - _self.delay = delayed; + _self.delay = _self; _self.schedule = function(timeout) { if (timer == null) timer = setTimeout(callback, timeout || 0);