From 56c97c992c544111b69684133076f49b978d10c6 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Tue, 25 Jan 2011 21:37:19 +0100 Subject: [PATCH] move hidden text area over the cursor --- lib/ace/keyboard/textinput.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/ace/keyboard/textinput.js b/lib/ace/keyboard/textinput.js index 08812a0a..459f9e0e 100644 --- a/lib/ace/keyboard/textinput.js +++ b/lib/ace/keyboard/textinput.js @@ -43,11 +43,34 @@ var TextInput = function(parentNode, host) { var text = document.createElement("textarea"); var style = text.style; - style.position = "absolute"; + 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.zIndex = -1; + style.opacity = 0; + style.width = "10px"; + style.height = "30px"; + + var changeCursor = function() { + 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); + }); + var PLACEHOLDER = String.fromCharCode(0); sendText();