From 9db4c1d1f48eeb926ee0cc2945e6f7201e452a2e Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Thu, 27 Jan 2011 18:01:00 +0100 Subject: [PATCH] moving the textarea over the cursor belongs to the renderer --- lib/ace/editor.js | 7 ++++++- lib/ace/keyboard/textinput.js | 32 +++++++------------------------- lib/ace/virtual_renderer.js | 13 +++++++++++++ 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 00447554..5e8f2a01 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -56,7 +56,7 @@ var Editor =function(renderer, session) { this.container = container; this.renderer = renderer; - this.textInput = new TextInput(container, this); + this.textInput = new TextInput(renderer.getTextAreaContainer(), this); this.keyBinding = new KeyBinding(this); var self = this; event.addListener(container, "mousedown", function(e) { @@ -281,6 +281,11 @@ var Editor =function(renderer, session) { this.onCursorChange = function(e) { this.$highlightBrackets(); + + // move text input over the cursor + // this is required for iOS and IME + this.renderer.moveTextAreaToCursor(this.textInput.getElement()); + this.renderer.updateCursor(this.getCursorPosition(), this.$overwrite); if (!this.$blockScrolling && (!e || !e.blockScrolling)) { diff --git a/lib/ace/keyboard/textinput.js b/lib/ace/keyboard/textinput.js index b6faa25f..0cc2465b 100644 --- a/lib/ace/keyboard/textinput.js +++ b/lib/ace/keyboard/textinput.js @@ -43,35 +43,13 @@ var TextInput = function(parentNode, host) { var text = document.createElement("textarea"); var style = text.style; - style.position = "fixed"; - style.left = "-10000px"; - style.top = "-10000px"; - parentNode.appendChild(text); - - // move text input over the cursor - // this is required for iOS and IME - style.left = "0px"; - style.top = "0px"; + style.position = "absolute"; style.zIndex = -1; style.opacity = 0; + style.border = "none"; style.width = "10px"; style.height = "30px"; - - var changeCursor = function() { - if (host.renderer.isMockRenderer) return; - - var cursor = host.getCursorPosition(); - var pos = host.renderer.textToScreenCoordinates(cursor.row, cursor.column); - var epos = parentNode.getBoundingClientRect(); - style.left = (pos.pageX - epos.left - 6) + "px"; - style.top = (pos.pageY - epos.top + 52) + "px"; - }; - - host.addEventListener("changeSession", function(e) { - if (e.oldSession) - e.oldSession.getSelection().removeEventListener("changeCursor", changeCursor); - e.session.getSelection().addEventListener("changeCursor", changeCursor); - }); + parentNode.appendChild(text); var PLACEHOLDER = String.fromCharCode(0); sendText(); @@ -182,6 +160,10 @@ var TextInput = function(parentNode, host) { this.blur = function() { text.blur(); }; + + this.getElement = function() { + return text; + }; }; exports.TextInput = TextInput; diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index 69192951..c5690a51 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -291,6 +291,19 @@ var VirtualRenderer = function(container, theme) { this.getMouseEventTarget = function() { return this.content; }; + + this.getTextAreaContainer = function() { + return this.scroller; + }; + + this.moveTextAreaToCursor = function(textarea) { + var pos = this.$cursorLayer.getPixelPosition(); + if (!pos) + return; + + textarea.style.left = (pos.left + this.$padding) + "px"; + textarea.style.top = pos.top + "px"; + }; this.getFirstVisibleRow = function() { return (this.layerConfig || {}).firstRow || 0;