add option to autoresize editor vertically

This commit is contained in:
nightwing 2013-06-25 20:59:06 +04:00
commit 0479acfea7
6 changed files with 62 additions and 148 deletions

View file

@ -187,21 +187,21 @@ var VirtualRenderer = function(container, theme) {
this.CHANGE_FULL = 512;
this.CHANGE_H_SCROLL = 1024;
this.$logChanges = function(changes) {
var a = ""
if (changes & this.CHANGE_CURSOR) a += " cursor";
if (changes & this.CHANGE_MARKER) a += " marker";
if (changes & this.CHANGE_GUTTER) a += " gutter";
if (changes & this.CHANGE_SCROLL) a += " scroll";
if (changes & this.CHANGE_LINES) a += " lines";
if (changes & this.CHANGE_TEXT) a += " text";
if (changes & this.CHANGE_SIZE) a += " size";
if (changes & this.CHANGE_MARKER_BACK) a += " marker_back";
if (changes & this.CHANGE_MARKER_FRONT) a += " marker_front";
if (changes & this.CHANGE_FULL) a += " full";
if (changes & this.CHANGE_H_SCROLL) a += " h_scroll";
console.log(a.trim())
};
// this.$logChanges = function(changes) {
// var a = ""
// if (changes & this.CHANGE_CURSOR) a += " cursor";
// if (changes & this.CHANGE_MARKER) a += " marker";
// if (changes & this.CHANGE_GUTTER) a += " gutter";
// if (changes & this.CHANGE_SCROLL) a += " scroll";
// if (changes & this.CHANGE_LINES) a += " lines";
// if (changes & this.CHANGE_TEXT) a += " text";
// if (changes & this.CHANGE_SIZE) a += " size";
// if (changes & this.CHANGE_MARKER_BACK) a += " marker_back";
// if (changes & this.CHANGE_MARKER_FRONT) a += " marker_front";
// if (changes & this.CHANGE_FULL) a += " full";
// if (changes & this.CHANGE_H_SCROLL) a += " h_scroll";
// console.log(a.trim())
// };
oop.implement(this, EventEmitter);
@ -569,8 +569,6 @@ var VirtualRenderer = function(container, theme) {
// move text input over the cursor
// this is required for iOS and IME
this.$moveTextAreaToCursor = function() {
this.textarea.style.cssText = "top:0;left:0;position:fixed"
return
if (!this.$keepTextAreaAtCursor)
return;
var config = this.layerConfig;
@ -657,7 +655,7 @@ var VirtualRenderer = function(container, theme) {
this.$updatePrintMargin();
};
this.setScrollMargin = function(top, left, bottom, right) {
this.setScrollMargin = function(top, bottom, left, right) {
var sm = this.scrollMargin;
sm.top = top|0;
sm.bottom = bottom|0;
@ -714,7 +712,7 @@ var VirtualRenderer = function(container, theme) {
return;
}
this.$logChanges(changes);
// this.$logChanges(changes);
this._signal("beforeRender");
// text, scrolling and resize changes can cause the view port size to change
@ -807,50 +805,55 @@ var VirtualRenderer = function(container, theme) {
};
this.setSize = function(height, width) {
this.scrollBar.element.style.display = "";
this.scrollBar.width = this.scrollBar.orginalWidth;
this.container.style.height = config.height + "px";
this.$autosize = function(height, width) {
var height = this.session.getScreenLength() * this.lineHeight;
var maxHeight = this.$maxLines * this.lineHeight;
var desiredHeight = Math.max(this.lineHeight, Math.min(maxHeight, height));
var vScroll = height > maxHeight;
this.scrollTop = height - this.maxLines * this.lineHeight;
if (desiredHeight != this.desiredHeight ||
this.$size.height != this.desiredHeight || vScroll != this.$vScroll) {
if (vScroll != this.$vScroll) {
this.$vScroll = vScroll;
this.scrollBarV.setVisible(vScroll);
}
this.container.style.height = desiredHeight + "px";
this.$updateCachedSize(true, this.$gutterWidth, this.$size.width, desiredHeight);
// this.$loop.changes = 0;
this.desiredHeight = desiredHeight;
}
};
this.$computeLayerConfig = function() {
if (this.$maxLines && this.lineHeight > 1)
this.$autosize();
if (!this.$size.scrollerHeight)
return this.onResize(true);
var session = this.session;
var hideScrollbars = this.$size.height <= 2 * this.lineHeight;
var screenLines = this.session.getScreenLength()
if (this.$size.maxLines) {
var underflow = screenLines < this.$size.maxLines;
if (underflow != this.underflow) {
} else if (true) {
}
}
var maxHeight = screenLines * this.lineHeight;
var offset = this.scrollTop % this.lineHeight;
var minHeight = this.$size.scrollerHeight + this.lineHeight;
var longestLine = this.$getLongestLine();
var horizScroll = !hideScrollbars && (this.$hScrollBarAlwaysVisible ||
this.$size.scrollerWidth - longestLine - 2 * this.$padding < 0);
var horizScroll = this.$size.scrollerWidth - longestLine - 2 * this.$padding < 0;
if (!horizScroll && this.$hScrollBarAlwaysVisible)
horizScroll = true;
var horizScrollChanged = this.$horizScroll !== horizScroll;
if (horizScrollChanged) {
var hScrollChanged = this.$horizScroll !== horizScroll;
if (hScrollChanged) {
this.$horizScroll = horizScroll;
this.scrollBarH.setVisible(horizScroll);
}
var vScroll = this.$vScrollBarAlwaysVisible || this.$size.scrollerHeight - maxHeight < 0;
var vScroll = !hideScrollbars && (this.$vScrollBarAlwaysVisible ||
this.$size.scrollerHeight - maxHeight < 0);
var vScrollChanged = this.$vScroll !== vScroll;
if (vScrollChanged) {
this.$vScroll = vScroll;
@ -859,7 +862,7 @@ var VirtualRenderer = function(container, theme) {
this.session.setScrollTop(Math.max(-this.scrollMargin.top,
Math.min(this.scrollTop, maxHeight - this.$size.scrollerHeight + this.scrollMargin.v)));
console.log(longestLine , this.$size.scrollerWidth)
this.session.setScrollLeft(Math.max(-this.scrollMargin.left, Math.min(this.scrollLeft,
longestLine + 2 * this.$padding - this.$size.scrollerWidth + this.scrollMargin.h)));
@ -912,8 +915,10 @@ var VirtualRenderer = function(container, theme) {
// Horizontal scrollbar visibility may have changed, which changes
// the client height of the scroller
if (horizScrollChanged || vScrollChanged)
if (hScrollChanged || vScrollChanged) {
this.onResize(true);
this._signal("scrollbarVisibilityChanged");
}
};
this.$updateLines = function() {
@ -1068,6 +1073,8 @@ var VirtualRenderer = function(container, theme) {
this.session.setScrollLeft(left);
} else if (scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) {
this.session.setScrollLeft(Math.round(left + this.characterWidth - this.$size.scrollerWidth));
} else if (scrollLeft <= this.$padding && left - scrollLeft < this.characterWidth) {
this.session.setScrollLeft(0);
}
};