This commit is contained in:
Fabian Jakobs 2011-06-08 15:26:16 +00:00
commit 8d45513f62
2 changed files with 34 additions and 27 deletions

View file

@ -507,8 +507,8 @@ var Editor =function(renderer, session) {
if (shouldOutdent) { if (shouldOutdent) {
mode.autoOutdent(lineState, session, cursor.row); mode.autoOutdent(lineState, session, cursor.row);
} }
}; }
} };
this.onTextInput = function(text) { this.onTextInput = function(text) {
this.keyBinding.onTextInput(text); this.keyBinding.onTextInput(text);

View file

@ -278,7 +278,7 @@ var VirtualRenderer = function(container, theme) {
this.getShowGutter = function(){ this.getShowGutter = function(){
return this.showGutter; return this.showGutter;
} };
this.setShowGutter = function(show){ this.setShowGutter = function(show){
if(this.showGutter === show) if(this.showGutter === show)
@ -286,10 +286,10 @@ var VirtualRenderer = function(container, theme) {
this.$gutter.style.display = show ? "block" : "none"; this.$gutter.style.display = show ? "block" : "none";
this.showGutter = show; this.showGutter = show;
this.onResize(true); this.onResize(true);
} };
this.$updatePrintMargin = function() { this.$updatePrintMargin = function() {
var containerEl var containerEl;
if (!this.$showPrintMargin && !this.$printMarginEl) if (!this.$showPrintMargin && !this.$printMarginEl)
return; return;
@ -297,7 +297,7 @@ var VirtualRenderer = function(container, theme) {
if (!this.$printMarginEl) { if (!this.$printMarginEl) {
containerEl = dom.createElement("div"); containerEl = dom.createElement("div");
containerEl.className = "ace_print_margin_layer"; containerEl.className = "ace_print_margin_layer";
this.$printMarginEl = dom.createElement("div") this.$printMarginEl = dom.createElement("div");
this.$printMarginEl.className = "ace_print_margin"; this.$printMarginEl.className = "ace_print_margin";
containerEl.appendChild(this.$printMarginEl); containerEl.appendChild(this.$printMarginEl);
this.content.insertBefore(containerEl, this.$textLayer.element); this.content.insertBefore(containerEl, this.$textLayer.element);
@ -344,8 +344,8 @@ var VirtualRenderer = function(container, theme) {
if (!this.layerConfig) if (!this.layerConfig)
return 0; return 0;
return this.layerConfig.firstRow + (this.layerConfig.offset == 0 ? 0 : 1); return this.layerConfig.firstRow + (this.layerConfig.offset === 0 ? 0 : 1);
} };
this.getLastFullyVisibleRow = function() { this.getLastFullyVisibleRow = function() {
if (!this.layerConfig) if (!this.layerConfig)
@ -353,7 +353,7 @@ var VirtualRenderer = function(container, theme) {
var flint = Math.floor((this.layerConfig.height + this.layerConfig.offset) / this.layerConfig.lineHeight); var flint = Math.floor((this.layerConfig.height + this.layerConfig.offset) / this.layerConfig.lineHeight);
return this.layerConfig.firstRow - 1 + flint; return this.layerConfig.firstRow - 1 + flint;
} };
this.getLastVisibleRow = function() { this.getLastVisibleRow = function() {
return (this.layerConfig || {}).lastRow || 0; return (this.layerConfig || {}).lastRow || 0;
@ -369,7 +369,7 @@ var VirtualRenderer = function(container, theme) {
this.getHScrollBarAlwaysVisible = function() { this.getHScrollBarAlwaysVisible = function() {
return this.$horizScrollAlwaysVisible; return this.$horizScrollAlwaysVisible;
} };
this.setHScrollBarAlwaysVisible = function(alwaysVisible) { this.setHScrollBarAlwaysVisible = function(alwaysVisible) {
if (this.$horizScrollAlwaysVisible != alwaysVisible) { if (this.$horizScrollAlwaysVisible != alwaysVisible) {
@ -377,7 +377,7 @@ var VirtualRenderer = function(container, theme) {
if (!this.$horizScrollAlwaysVisible || !this.$horizScroll) if (!this.$horizScrollAlwaysVisible || !this.$horizScroll)
this.$loop.schedule(this.CHANGE_SCROLL); this.$loop.schedule(this.CHANGE_SCROLL);
} }
} };
this.onScroll = function(e) { this.onScroll = function(e) {
this.scrollToY(e.data); this.scrollToY(e.data);
@ -405,7 +405,8 @@ var VirtualRenderer = function(container, theme) {
// full // full
if (changes & this.CHANGE_FULL) { if (changes & this.CHANGE_FULL) {
this.$textLayer.update(this.layerConfig); this.$textLayer.update(this.layerConfig);
this.showGutter && this.$gutterLayer.update(this.layerConfig); if (this.showGutter)
this.$gutterLayer.update(this.layerConfig);
this.$markerBack.update(this.layerConfig); this.$markerBack.update(this.layerConfig);
this.$markerFront.update(this.layerConfig); this.$markerFront.update(this.layerConfig);
this.$cursorLayer.update(this.layerConfig); this.$cursorLayer.update(this.layerConfig);
@ -419,7 +420,9 @@ var VirtualRenderer = function(container, theme) {
this.$textLayer.update(this.layerConfig); this.$textLayer.update(this.layerConfig);
else else
this.$textLayer.scrollLines(this.layerConfig); this.$textLayer.scrollLines(this.layerConfig);
this.showGutter && this.$gutterLayer.update(this.layerConfig);
if (this.showGutter)
this.$gutterLayer.update(this.layerConfig);
this.$markerBack.update(this.layerConfig); this.$markerBack.update(this.layerConfig);
this.$markerFront.update(this.layerConfig); this.$markerFront.update(this.layerConfig);
this.$cursorLayer.update(this.layerConfig); this.$cursorLayer.update(this.layerConfig);
@ -429,14 +432,17 @@ var VirtualRenderer = function(container, theme) {
if (changes & this.CHANGE_TEXT) { if (changes & this.CHANGE_TEXT) {
this.$textLayer.update(this.layerConfig); this.$textLayer.update(this.layerConfig);
this.showGutter && this.$gutterLayer.update(this.layerConfig); if (this.showGutter)
this.$gutterLayer.update(this.layerConfig);
} }
else if (changes & this.CHANGE_LINES) { else if (changes & this.CHANGE_LINES) {
this.$updateLines(); this.$updateLines();
this.$updateScrollBar(); this.$updateScrollBar();
this.showGutter && this.$gutterLayer.update(this.layerConfig); if (this.showGutter)
this.$gutterLayer.update(this.layerConfig);
} else if (changes & this.CHANGE_GUTTER) { } else if (changes & this.CHANGE_GUTTER) {
this.showGutter && this.$gutterLayer.update(this.layerConfig); if (this.showGutter)
this.$gutterLayer.update(this.layerConfig);
} }
if (changes & this.CHANGE_CURSOR) if (changes & this.CHANGE_CURSOR)
@ -547,7 +553,8 @@ var VirtualRenderer = function(container, theme) {
// if the last row is unknown -> redraw everything // if the last row is unknown -> redraw everything
if (lastRow === Infinity) { if (lastRow === Infinity) {
this.showGutter && this.$gutterLayer.update(layerConfig); if (this.showGutter)
this.$gutterLayer.update(layerConfig);
this.$textLayer.update(layerConfig); this.$textLayer.update(layerConfig);
return; return;
} }
@ -577,12 +584,12 @@ var VirtualRenderer = function(container, theme) {
this.addGutterDecoration = function(row, className){ this.addGutterDecoration = function(row, className){
this.$gutterLayer.addGutterDecoration(row, className); this.$gutterLayer.addGutterDecoration(row, className);
this.$loop.schedule(this.CHANGE_GUTTER); this.$loop.schedule(this.CHANGE_GUTTER);
} };
this.removeGutterDecoration = function(row, className){ this.removeGutterDecoration = function(row, className){
this.$gutterLayer.removeGutterDecoration(row, className); this.$gutterLayer.removeGutterDecoration(row, className);
this.$loop.schedule(this.CHANGE_GUTTER); this.$loop.schedule(this.CHANGE_GUTTER);
} };
this.setBreakpoints = function(rows) { this.setBreakpoints = function(rows) {
this.$gutterLayer.setBreakpoints(rows); this.$gutterLayer.setBreakpoints(rows);
@ -636,7 +643,7 @@ var VirtualRenderer = function(container, theme) {
else else
this.scrollToX(Math.round(left + this.characterWidth - this.$size.scrollerWidth)); this.scrollToX(Math.round(left + this.characterWidth - this.$size.scrollerWidth));
} }
}, };
this.getScrollTop = function() { this.getScrollTop = function() {
return this.scrollTop; return this.scrollTop;
@ -652,7 +659,7 @@ var VirtualRenderer = function(container, theme) {
this.getScrollBottomRow = function() { this.getScrollBottomRow = function() {
return Math.max(0, Math.floor((this.scrollTop + this.$size.scrollerHeight) / this.lineHeight) - 1); return Math.max(0, Math.floor((this.scrollTop + this.$size.scrollerHeight) / this.lineHeight) - 1);
} };
this.scrollToRow = function(row) { this.scrollToRow = function(row) {
this.scrollToY(row * this.lineHeight); this.scrollToY(row * this.lineHeight);
@ -714,7 +721,7 @@ var VirtualRenderer = function(container, theme) {
return { return {
pageX: canvasPos.left + x - this.getScrollLeft(), pageX: canvasPos.left + x - this.getScrollLeft(),
pageY: canvasPos.top + y - this.getScrollTop() pageY: canvasPos.top + y - this.getScrollTop()
} };
}; };
this.visualizeFocus = function() { this.visualizeFocus = function() {
@ -760,6 +767,7 @@ var VirtualRenderer = function(container, theme) {
this.setTheme = function(theme) { this.setTheme = function(theme) {
var _self = this; var _self = this;
this.$themeValue = theme; this.$themeValue = theme;
if (!theme || typeof theme == "string") { if (!theme || typeof theme == "string") {
theme = theme || "ace/theme/textmate"; theme = theme || "ace/theme/textmate";
@ -770,7 +778,6 @@ var VirtualRenderer = function(container, theme) {
afterLoad(theme); afterLoad(theme);
} }
var _self = this;
function afterLoad(theme) { function afterLoad(theme) {
if (_self.$theme) if (_self.$theme)
dom.removeCssClass(_self.container, _self.$theme); dom.removeCssClass(_self.container, _self.$theme);
@ -790,24 +797,24 @@ var VirtualRenderer = function(container, theme) {
this.getTheme = function() { this.getTheme = function() {
return this.$themeValue; return this.$themeValue;
} };
// Methods allows to add / remove CSS classnames to the editor element. // Methods allows to add / remove CSS classnames to the editor element.
// This feature can be used by plug-ins to provide a visual indication of // This feature can be used by plug-ins to provide a visual indication of
// a certain mode that editor is in. // a certain mode that editor is in.
this.setStyle = function setStyle(style) { this.setStyle = function setStyle(style) {
dom.addCssClass(this.container, style) dom.addCssClass(this.container, style);
}; };
this.unsetStyle = function unsetStyle(style) { this.unsetStyle = function unsetStyle(style) {
dom.removeCssClass(this.container, style) dom.removeCssClass(this.container, style);
}; };
this.destroy = function() { this.destroy = function() {
this.$textLayer.destroy(); this.$textLayer.destroy();
this.$cursorLayer.destroy(); this.$cursorLayer.destroy();
} };
}).call(VirtualRenderer.prototype); }).call(VirtualRenderer.prototype);