From d437b63d194190a53ea7a1a77269dbb9618f3566 Mon Sep 17 00:00:00 2001 From: nightwing Date: Fri, 25 Jan 2013 18:39:18 +0400 Subject: [PATCH] position textarea with bottom/right since otherwise firefox 21+ scrolls editor out of view when textarea.focus is called --- lib/ace/css/editor.css | 8 +++++--- lib/ace/keyboard/textinput.js | 8 +++----- lib/ace/virtual_renderer.js | 19 ++++++++++--------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/lib/ace/css/editor.css b/lib/ace/css/editor.css index c1dd818a..4b6c8e42 100644 --- a/lib/ace/css/editor.css +++ b/lib/ace/css/editor.css @@ -98,15 +98,17 @@ resize: none; outline: none; overflow: hidden; + font: inherit; } .ace_text-input.ace_composition { - background: #fff; - color: #000; + background: #f8f8f8; + color: #111; z-index: 1000; opacity: 1; border: solid lightgray 1px; - margin: -1px + margin: -1px; + padding: 0 1px; } .ace_layer { diff --git a/lib/ace/keyboard/textinput.js b/lib/ace/keyboard/textinput.js index 6264eacb..cda58170 100644 --- a/lib/ace/keyboard/textinput.js +++ b/lib/ace/keyboard/textinput.js @@ -51,7 +51,7 @@ var TextInput = function(parentNode, host) { text.autocapitalize = "off"; text.spellcheck = false; - text.style.top = "-2em"; + text.style.bottom = "-2em"; parentNode.insertBefore(text, parentNode.firstChild); var PLACEHOLDER = "\x01\x01"; @@ -350,12 +350,10 @@ var TextInput = function(parentNode, host) { host.onCompositionEnd(); }; + var syncComposition = lang.delayedCall(onCompositionUpdate, 50); event.addListener(text, "compositionstart", onCompositionStart); - if (useragent.isGecko) - event.addListener(text, "text", onCompositionUpdate); - else - event.addListener(text, "keyup", onCompositionUpdate); + event.addListener(text, useragent.isGecko ? "text" : "keyup", function(){syncComposition.schedule()}); event.addListener(text, "compositionend", onCompositionEnd); this.getElement = function() { diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index 75860d92..6192b133 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -566,28 +566,29 @@ var VirtualRenderer = function(container, theme) { this.$moveTextAreaToCursor = function() { if (!this.$keepTextAreaAtCursor) return; - + var config = this.layerConfig; var posTop = this.$cursorLayer.$pixelPos.top; var posLeft = this.$cursorLayer.$pixelPos.left; - posTop -= this.layerConfig.offset; + posTop -= config.offset; - if (posTop < 0 || posTop > this.layerConfig.height - this.lineHeight) + if (posTop < 0 || posTop > config.height - this.lineHeight) return; var w = this.characterWidth; - if (this.$composition) - w += this.textarea.scrollWidth; + if (this.$composition) { + var val = this.textarea.value.replace(/^\x01+/, ""); + w *= this.session.$getStringScreenWidth(val)[0]; + } posLeft -= this.scrollLeft; if (posLeft > this.$size.scrollerWidth - w) posLeft = this.$size.scrollerWidth - w; - if (this.showGutter) - posLeft += this.$gutterLayer.gutterWidth; + posLeft -= this.scrollBar.width; this.textarea.style.height = this.lineHeight + "px"; this.textarea.style.width = w + "px"; - this.textarea.style.left = posLeft + "px"; - this.textarea.style.top = posTop - 1 + "px"; + this.textarea.style.right = this.$size.scrollerWidth - posLeft - w + "px"; + this.textarea.style.bottom = this.$size.height - posTop - this.lineHeight + "px"; }; /**