Merge branch 'ui/navbar'

Conflicts:
	build/demo/kitchen-sink/kitchen-sink-uncompressed.js
	build/src/ace-uncompressed-noconflict.js
	build/src/ace-uncompressed.js
	build/textarea/src/ace-bookmarklet.js
	lib/ace/edit_session.js
	lib/ace/editor.js
	lib/ace/multi_select.js
	lib/ace/selection.js
	lib/ace/virtual_renderer.js
This commit is contained in:
Fabian Jakobs 2012-05-01 11:30:17 +02:00
commit 43c4a8fc35
29 changed files with 630 additions and 287 deletions

View file

@ -101,6 +101,7 @@ var VirtualRenderer = function(container, theme) {
this.$gutterLayer = new GutterLayer(this.$gutter);
this.$gutterLayer.on("changeGutterWidth", this.onResize.bind(this, true));
this.setFadeFoldWidgets(true);
this.$markerBack = new MarkerLayer(this.content);
@ -116,14 +117,15 @@ var VirtualRenderer = function(container, theme) {
this.$cursorPadding = 8;
// Indicates whether the horizontal scrollbar is visible
this.$horizScroll = true;
this.$horizScrollAlwaysVisible = true;
this.$horizScroll = false;
this.$horizScrollAlwaysVisible = false;
this.$animatedScroll = false;
this.scrollBar = new ScrollBar(container);
this.scrollBar.addEventListener("scroll", function(e) {
_self.session.setScrollTop(e.data);
if (!_self.$inScrollAnimation)
_self.session.setScrollTop(e.data);
});
this.scrollTop = 0;
@ -134,12 +136,9 @@ var VirtualRenderer = function(container, theme) {
_self.scrollLeft = scrollLeft;
_self.session.setScrollLeft(scrollLeft);
if (scrollLeft == 0) {
_self.$gutter.className = "ace_gutter";
}
else {
_self.$gutter.className = "ace_gutter horscroll";
}
_self.scroller.className = scrollLeft == 0
? "ace_scroller"
: "ace_scroller horscroll";
});
this.cursorPos = {
@ -211,12 +210,16 @@ var VirtualRenderer = function(container, theme) {
**/
this.setSession = function(session) {
this.session = session;
this.scroller.className = "ace_scroller";
this.$cursorLayer.setSession(session);
this.$markerBack.setSession(session);
this.$markerFront.setSession(session);
this.$gutterLayer.setSession(session);
this.$textLayer.setSession(session);
this.$loop.schedule(this.CHANGE_FULL);
};
/**
@ -435,6 +438,17 @@ var VirtualRenderer = function(container, theme) {
this.onResize(true);
};
this.getFadeFoldWidgets = function(){
return dom.hasCssClass(this.$gutter, "ace_fade-fold-widgets");
};
this.setFadeFoldWidgets = function(show) {
if (show)
dom.addCssClass(this.$gutter, "ace_fade-fold-widgets");
else
dom.removeCssClass(this.$gutter, "ace_fade-fold-widgets");
};
this.$updatePrintMargin = function() {
var containerEl;
@ -878,18 +892,18 @@ var VirtualRenderer = function(container, theme) {
this.$cursorLayer.showCursor();
};
this.scrollSelectionIntoView = function(anchor, lead) {
this.scrollSelectionIntoView = function(anchor, lead, offset) {
// first scroll anchor into view then scroll lead into view
this.scrollCursorIntoView(anchor);
this.scrollCursorIntoView(lead);
this.scrollCursorIntoView(anchor, offset);
this.scrollCursorIntoView(lead, offset);
};
/**
* VirtualRenderer.scrollCursorIntoView() -> Void
* VirtualRenderer.scrollCursorIntoView(cursor, offset) -> Void
*
* Scrolls the cursor into the first visibile area of the editor
**/
this.scrollCursorIntoView = function(cursor) {
this.scrollCursorIntoView = function(cursor, offset) {
// the editor is not visible
if (this.$size.scrollerHeight === 0)
return;
@ -900,10 +914,12 @@ var VirtualRenderer = function(container, theme) {
var top = pos.top;
if (this.scrollTop > top) {
if (offset)
top -= offset * this.$size.scrollerHeight;
this.session.setScrollTop(top);
}
if (this.scrollTop + this.$size.scrollerHeight < top + this.lineHeight) {
} else if (this.scrollTop + this.$size.scrollerHeight < top + this.lineHeight) {
if (offset)
top += offset * this.$size.scrollerHeight;
this.session.setScrollTop(top + this.lineHeight - this.$size.scrollerHeight);
}
@ -913,9 +929,7 @@ var VirtualRenderer = function(container, theme) {
if (left < this.$padding + 2 * this.layerConfig.characterWidth)
left = 0;
this.session.setScrollLeft(left);
}
if (scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) {
} else if (scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) {
this.session.setScrollLeft(Math.round(left + this.characterWidth - this.$size.scrollerWidth));
}
};
@ -966,36 +980,70 @@ var VirtualRenderer = function(container, theme) {
this.session.setScrollTop(row * this.lineHeight);
};
this.STEPS = 8;
this.$calcSteps = function(fromValue, toValue){
var i = 0;
var l = this.STEPS;
var steps = [];
var func = function(t, x_min, dx) {
return dx * (Math.pow(t - 1, 3) + 1) + x_min;
};
for (i = 0; i < l; ++i)
steps.push(func(i / this.STEPS, fromValue, toValue - fromValue));
return steps;
};
/**
* VirtualRenderer.scrollToLine(line, center) -> Void
* VirtualRenderer.scrollToLine(line, center, animate, callback) -> Void
* - line (Number): A line number
* - center (Boolean): If `true`, centers the editor the to indicated line
*
* - animate (Boolean): If `true` animates scrolling
* - callback (Function): Function to be called after the animation has finished
*
* Gracefully scrolls the editor to the row indicated.
**/
this.scrollToLine = function(line, center) {
this.scrollToLine = function(line, center, animate, callback) {
var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0});
var offset = pos.top;
if (center)
offset -= this.$size.scrollerHeight / 2;
if (this.$animatedScroll && Math.abs(offset - this.scrollTop) < 10000) {
var _self = this;
var steps = _self.$calcSteps(this.scrollTop, offset);
clearInterval(this.$timer);
this.$timer = setInterval(function() {
_self.session.setScrollTop(steps.shift());
if (!steps.length)
clearInterval(_self.$timer);
}, 10);
}
else {
var initialScroll = this.scrollTop;
this.session.setScrollTop(offset);
}
if (animate !== false)
this.animateScrolling(initialScroll, callback);
};
this.animateScrolling = function(fromValue, callback) {
var toValue = this.scrollTop;
if (this.$animatedScroll && Math.abs(fromValue - toValue) < 100000) {
var _self = this;
var steps = _self.$calcSteps(fromValue, toValue);
this.$inScrollAnimation = true;
clearInterval(this.$timer);
_self.session.setScrollTop(steps.shift());
this.$timer = setInterval(function() {
if (steps.length) {
_self.session.setScrollTop(steps.shift());
// trick session to think it's already scrolled to not loose toValue
_self.session.$scrollTop = toValue;
} else {
this.$inScrollAnimation = false;
clearInterval(_self.$timer);
_self.session.$scrollTop = -1;
_self.session.setScrollTop(toValue);
callback && callback();
}
}, 10);
}
};
/**
* VirtualRenderer.scrollToY(scrollTop) -> Number
* - scrollTop (Number): The position to scroll to