fix unwanted scrolling into view of hidden textarea

This commit is contained in:
nightwing 2014-11-13 23:57:10 +04:00
commit 1721ca8a0c
3 changed files with 18 additions and 11 deletions

View file

@ -75,7 +75,14 @@ var TextInput = function(parentNode, host) {
host.onFocus(e); host.onFocus(e);
resetSelection(); resetSelection();
}); });
this.focus = function() { text.focus(); }; this.focus = function() {
text.style.position = "fixed";
text.style.top = "-10000000px";
text.focus();
setTimeout(function() {
text.style.position = "";
}, 0);
};
this.blur = function() { text.blur(); }; this.blur = function() { text.blur(); };
this.isFocused = function() { this.isFocused = function() {
return isFocused; return isFocused;

View file

@ -47,10 +47,8 @@ var MouseHandler = function(editor) {
new DefaultGutterHandler(this); new DefaultGutterHandler(this);
new DragdropHandler(this); new DragdropHandler(this);
var focusEditor = function(e) { var focusEditor = function(e) {
if (!editor.isFocused() && editor.textInput) editor.focus();
editor.textInput.moveToMouse(e);
editor.focus()
}; };
var mouseTarget = editor.renderer.getMouseEventTarget(); var mouseTarget = editor.renderer.getMouseEventTarget();

View file

@ -634,9 +634,12 @@ var VirtualRenderer = function(container, theme) {
var posLeft = this.$cursorLayer.$pixelPos.left; var posLeft = this.$cursorLayer.$pixelPos.left;
posTop -= config.offset; posTop -= config.offset;
var style = this.textarea.style;
var h = this.lineHeight; var h = this.lineHeight;
if (posTop < 0 || posTop > config.height - h) if (posTop < 0 || posTop > config.height - h) {
style.top = style.left = "0";
return; return;
}
var w = this.characterWidth; var w = this.characterWidth;
if (this.$composition) { if (this.$composition) {
@ -649,11 +652,10 @@ var VirtualRenderer = function(container, theme) {
posLeft = this.$size.scrollerWidth - w; posLeft = this.$size.scrollerWidth - w;
posLeft += this.gutterWidth; posLeft += this.gutterWidth;
style.height = h + "px";
this.textarea.style.height = h + "px"; style.width = w + "px";
this.textarea.style.width = w + "px"; style.left = Math.min(posLeft, this.$size.scrollerWidth - w) + "px";
this.textarea.style.left = Math.min(posLeft, this.$size.scrollerWidth - w) + "px"; style.top = Math.min(posTop, this.$size.height - h) + "px";
this.textarea.style.top = Math.min(posTop, this.$size.height - h) + "px";
}; };
/** /**