From 125629ce1720418f6be0fe56190981c57efaf40e Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 9 Dec 2012 23:16:09 +0400 Subject: [PATCH] cleanup --- lib/ace/keyboard/textinput.js | 78 ++++++++++++++++------------------- 1 file changed, 36 insertions(+), 42 deletions(-) diff --git a/lib/ace/keyboard/textinput.js b/lib/ace/keyboard/textinput.js index db2a6468..7e5b0ebe 100644 --- a/lib/ace/keyboard/textinput.js +++ b/lib/ace/keyboard/textinput.js @@ -3,7 +3,7 @@ * * Copyright (c) 2010, Ajax.org B.V. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ * * Neither the name of Ajax.org B.V. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * + * * 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 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -40,16 +40,13 @@ var TextInput = function(parentNode, host) { var text = dom.createElement("textarea"); text.className = "ace_text-input"; /*/ debug - text.style.opacity = 1 - text.style.background = "rgba(0, 250, 0, 0.3)" - text.style.outline = "rgba(0, 250, 0, 0.8) solid 1px" - text.style.outlineOffset = "3px" + 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"; /**/ if (useragent.isTouchPad) text.setAttribute("x-palm-disable-auto-cap", true); text.wrap = "off"; - text.autocorrect = "off"; + text.autocorrect = "off"; text.autocapitalize = "off"; text.spellcheck = false; @@ -58,7 +55,7 @@ var TextInput = function(parentNode, host) { var PLACEHOLDER = "\x01\x01"; - var cut = false + var cut = false; var copied = false; var pasted = false; var inCompostion = false; @@ -76,12 +73,8 @@ var TextInput = function(parentNode, host) { host.onFocus(); resetSelection(); }); - this.focus = function() { - text.focus(); - }; - this.blur = function() { - text.blur(); - }; + this.focus = function() { text.focus(); }; + this.blur = function() { text.blur(); }; this.isFocused = function() { return isFocused; }; @@ -106,7 +99,7 @@ var TextInput = function(parentNode, host) { try { text.setSelectionRange(selectionStart, selectionEnd); } catch(e){} - }; + } function resetValue() { if (inCompostion) @@ -115,7 +108,7 @@ var TextInput = function(parentNode, host) { //http://code.google.com/p/chromium/issues/detail?id=76516 if (useragent.isWebKit) syncValue.schedule(); - }; + } useragent.isWebKit || host.addEventListener('changeSelection', function() { if (host.selection.isEmpty() != isSelectionEmpty) { @@ -124,7 +117,6 @@ var TextInput = function(parentNode, host) { } }); - resetValue(); if (isFocused) host.onFocus(); @@ -132,7 +124,7 @@ var TextInput = function(parentNode, host) { var isAllSelected = function(text) { return text.selectionStart === 0 && text.selectionEnd === text.value.length; - } + }; // IE8 does not support setSelectionRange if (!text.setSelectionRange && text.createTextRange) { text.setSelectionRange = function(selectionStart, selectionEnd) { @@ -151,8 +143,6 @@ var TextInput = function(parentNode, host) { } } if (useragent.isOldIE) { - var syncProperty = lang.delayedCall(onPropertyChange); - var propertyChangeCounter = 0; var onPropertyChange = function(e){ if (propertyChangeCounter) return; @@ -167,7 +157,9 @@ var TextInput = function(parentNode, host) { propertyChangeCounter++; resetValue(); propertyChangeCounter--; - } + }; + var syncProperty = lang.delayedCall(onPropertyChange); + var propertyChangeCounter = 0; event.addListener(text, "propertychange", onPropertyChange); var keytable = { 13:1, 27:1 }; @@ -228,22 +220,6 @@ var TextInput = function(parentNode, host) { 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 data = host.getCopyText(); if (!data) { @@ -354,10 +330,27 @@ var TextInput = function(parentNode, host) { // 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); if (useragent.isGecko) event.addListener(text, "text", onCompositionUpdate); - if (useragent.isWebKit) + else event.addListener(text, "keyup", onCompositionUpdate); event.addListener(text, "compositionend", onCompositionEnd); @@ -370,8 +363,8 @@ var TextInput = function(parentNode, host) { if (!tempStyle) tempStyle = text.style.cssText; - text.style.cssText = "z-index:100000;" + - (useragent.isIE ? "opacity:0.1;" : "")// + "background:rgba(250, 0, 0, 0.3); opacity:1;" + text.style.cssText = "z-index:100000;" + (useragent.isIE ? "opacity:0.1;" : ""); + // text.style.cssText += "background:rgba(250, 0, 0, 0.3); opacity:1;"; resetSelection(host.selection.isEmpty()); host._emit("nativecontextmenu", {target: editor}); @@ -393,7 +386,8 @@ var TextInput = function(parentNode, host) { event.capture(host.container, move, onContextMenuClose); }; - this.onContextMenuClose = function() { + this.onContextMenuClose = onContextMenuClose; + function onContextMenuClose() { setTimeout(function () { if (tempStyle) { text.style.cssText = tempStyle; @@ -404,7 +398,7 @@ var TextInput = function(parentNode, host) { host.renderer.$moveTextAreaToCursor(); } }, 0); - }; + } // firefox fires contextmenu event after opening it if (!useragent.isGecko) {