minor updates

This commit is contained in:
Fabian Jakobs 2010-09-30 18:08:06 +02:00
commit 76bf0bb90c

View file

@ -10,7 +10,7 @@ require.def("ace/VirtualRenderer",
"ace/lib/oop", "ace/lib/oop",
"ace/lib/lang", "ace/lib/lang",
"ace/lib/dom", "ace/lib/dom",
"ace/lib/event", "ace/lib/event",
"ace/layer/Gutter", "ace/layer/Gutter",
"ace/layer/Marker", "ace/layer/Marker",
"ace/layer/Text", "ace/layer/Text",
@ -20,7 +20,7 @@ require.def("ace/VirtualRenderer",
"ace/MEventEmitter", "ace/MEventEmitter",
"text!ace/css/editor.css" "text!ace/css/editor.css"
], function( ], function(
oop, lang, dom, event, GutterLayer, MarkerLayer, TextLayer, oop, lang, dom, event, GutterLayer, MarkerLayer, TextLayer,
CursorLayer, ScrollBar, RenderLoop, MEventEmitter, editorCss) { CursorLayer, ScrollBar, RenderLoop, MEventEmitter, editorCss) {
// import CSS once // import CSS once
@ -73,21 +73,21 @@ var VirtualRenderer = function(container, theme) {
this.$textLayer.addEventListener("changeCharaterSize", function() { this.$textLayer.addEventListener("changeCharaterSize", function() {
self.characterWidth = textLayer.getCharacterWidth(); self.characterWidth = textLayer.getCharacterWidth();
self.lineHeight = textLayer.getLineHeight(); self.lineHeight = textLayer.getLineHeight();
self.$loop.schedule(self.CHANGE_FULL); self.$loop.schedule(self.CHANGE_FULL);
}); });
event.addListener(this.$gutter, "click", lang.bind(this.$onGutterClick, this)); event.addListener(this.$gutter, "click", lang.bind(this.$onGutterClick, this));
event.addListener(this.$gutter, "dblclick", lang.bind(this.$onGutterClick, this)); event.addListener(this.$gutter, "dblclick", lang.bind(this.$onGutterClick, this));
this.$size = { this.$size = {
width: 0, width: 0,
height: 0, height: 0,
scrollerHeight: 0, scrollerHeight: 0,
scrollerWidth: 0 scrollerWidth: 0
}; };
this.$updatePrintMargin(); this.$updatePrintMargin();
this.$loop = new RenderLoop(lang.bind(this.$renderChanges, this)); this.$loop = new RenderLoop(lang.bind(this.$renderChanges, this));
this.$loop.schedule(this.CHANGE_FULL); this.$loop.schedule(this.CHANGE_FULL);
}; };
@ -100,7 +100,7 @@ var VirtualRenderer = function(container, theme) {
this.CHANGE_SCROLL = 8; this.CHANGE_SCROLL = 8;
this.CHANGE_LINES = 16; this.CHANGE_LINES = 16;
this.CHANGE_TEXT = 32; this.CHANGE_TEXT = 32;
this.CHANGE_SIZE = 64 this.CHANGE_SIZE = 64;
this.CHANGE_FULL = 128; this.CHANGE_FULL = 128;
oop.implement(this, MEventEmitter); oop.implement(this, MEventEmitter);
@ -111,7 +111,7 @@ var VirtualRenderer = function(container, theme) {
this.$cursorLayer.setDocument(doc); this.$cursorLayer.setDocument(doc);
this.$markerLayer.setDocument(doc); this.$markerLayer.setDocument(doc);
this.$textLayer.setDocument(doc); this.$textLayer.setDocument(doc);
this.$loop.schedule(this.CHANGE_FULL); this.$loop.schedule(this.CHANGE_FULL);
}; };
@ -133,7 +133,7 @@ var VirtualRenderer = function(container, theme) {
this.$updateLines.lastRow = lastRow; this.$updateLines.lastRow = lastRow;
} }
this.$loop.schedule(this.CHANGE_FULL); this.$loop.schedule(this.CHANGE_LINES);
}; };
/** /**
@ -149,17 +149,17 @@ var VirtualRenderer = function(container, theme) {
this.updateFull = function() { this.updateFull = function() {
this.$loop.schedule(this.CHANGE_FULL); this.$loop.schedule(this.CHANGE_FULL);
}; };
/** /**
* Triggers resize of the editor * Triggers resize of the editor
*/ */
this.onResize = function() { this.onResize = function() {
this.$loop.schedule(this.CHANGE_SIZE); this.$loop.schedule(this.CHANGE_SIZE);
var height = dom.getInnerHeight(this.container); var height = dom.getInnerHeight(this.container);
if (this.$size.height != height) { if (this.$size.height != height) {
this.$size.height = height; this.$size.height = height;
this.scroller.style.height = height + "px"; this.scroller.style.height = height + "px";
this.scrollBar.setHeight(height); this.scrollBar.setHeight(height);
@ -177,14 +177,14 @@ var VirtualRenderer = function(container, theme) {
this.scroller.style.left = gutterWidth + "px"; this.scroller.style.left = gutterWidth + "px";
this.scroller.style.width = Math.max(0, width - gutterWidth - this.scrollBar.getWidth()) + "px"; this.scroller.style.width = Math.max(0, width - gutterWidth - this.scrollBar.getWidth()) + "px";
} }
this.$size.scrollerWidth = this.scroller.clientWidth; this.$size.scrollerWidth = this.scroller.clientWidth;
this.$size.scrollerHeight = this.scroller.clientHeight; this.$size.scrollerHeight = this.scroller.clientHeight;
}; };
this.setTokenizer = function(tokenizer) { this.setTokenizer = function(tokenizer) {
this.$textLayer.setTokenizer(tokenizer); this.$textLayer.setTokenizer(tokenizer);
this.$loop.schedule(this.CHANGE_TEXT); this.$loop.schedule(this.CHANGE_TEXT);
}; };
@ -205,7 +205,7 @@ var VirtualRenderer = function(container, theme) {
this.setShowInvisibles = function(showInvisibles) { this.setShowInvisibles = function(showInvisibles) {
this.$showInvisibles = showInvisibles; this.$showInvisibles = showInvisibles;
this.$textLayer.setShowInvisibles(showInvisibles); this.$textLayer.setShowInvisibles(showInvisibles);
this.$loop.schedule(this.CHANGE_TEXT); this.$loop.schedule(this.CHANGE_TEXT);
}; };
@ -281,12 +281,12 @@ var VirtualRenderer = function(container, theme) {
if (!this.layerConfig || if (!this.layerConfig ||
changes & this.CHANGE_FULL || changes & this.CHANGE_FULL ||
changes & this.CHANGE_SIZE || changes & this.CHANGE_SIZE ||
changes & this.CHANGE_TEXT || changes & this.CHANGE_TEXT ||
changes & this.CHANGE_LINES || changes & this.CHANGE_LINES ||
changes & this.CHANGE_SCROLL changes & this.CHANGE_SCROLL
) )
this.$computeLayerConfig(); this.$computeLayerConfig();
// full // full
if (changes & this.CHANGE_FULL) { if (changes & this.CHANGE_FULL) {
this.$textLayer.update(this.layerConfig); this.$textLayer.update(this.layerConfig);
@ -296,7 +296,7 @@ var VirtualRenderer = function(container, theme) {
this.$updateScrollBar(); this.$updateScrollBar();
return; return;
} }
// scrolling // scrolling
if (changes & this.CHANGE_SCROLL) { if (changes & this.CHANGE_SCROLL) {
if (changes & this.CHANGE_TEXT || changes & this.CHANGE_LINES) { if (changes & this.CHANGE_TEXT || changes & this.CHANGE_LINES) {
@ -314,7 +314,7 @@ var VirtualRenderer = function(container, theme) {
this.$updateScrollBar(); this.$updateScrollBar();
return; return;
} }
if (changes & this.CHANGE_TEXT) { if (changes & this.CHANGE_TEXT) {
this.$textLayer.update(this.layerConfig); this.$textLayer.update(this.layerConfig);
this.$gutterLayer.update(this.layerConfig); this.$gutterLayer.update(this.layerConfig);
@ -335,11 +335,11 @@ var VirtualRenderer = function(container, theme) {
if (changes & this.CHANGE_MARKER) { if (changes & this.CHANGE_MARKER) {
this.$markerLayer.update(this.layerConfig); this.$markerLayer.update(this.layerConfig);
} }
if (changes & this.CHANGE_SIZE) if (changes & this.CHANGE_SIZE)
this.$updateScrollBar(); this.$updateScrollBar();
}; };
this.$computeLayerConfig = function() { this.$computeLayerConfig = function() {
var offset = this.scrollTop % this.lineHeight; var offset = this.scrollTop % this.lineHeight;
var minHeight = this.$size.scrollerHeight + this.lineHeight; var minHeight = this.$size.scrollerHeight + this.lineHeight;
@ -359,7 +359,7 @@ var VirtualRenderer = function(container, theme) {
characterWidth : this.characterWidth, characterWidth : this.characterWidth,
minHeight : minHeight minHeight : minHeight
}; };
for ( var i = 0; i < this.layers.length; i++) { for ( var i = 0; i < this.layers.length; i++) {
var layer = this.layers[i]; var layer = this.layers[i];
if (widthChanged) { if (widthChanged) {
@ -367,16 +367,16 @@ var VirtualRenderer = function(container, theme) {
style.width = longestLine + "px"; style.width = longestLine + "px";
} }
}; };
this.$gutterLayer.element.style.marginTop = (-offset) + "px"; this.$gutterLayer.element.style.marginTop = (-offset) + "px";
this.content.style.marginTop = (-offset) + "px"; this.content.style.marginTop = (-offset) + "px";
this.content.style.height = minHeight + "px"; this.content.style.height = minHeight + "px";
}; };
this.$updateLines = function() { this.$updateLines = function() {
var firstRow = this.$updateLines.firstRow; var firstRow = this.$updateLines.firstRow;
var lastRow = this.$updateLines.lastRow; var lastRow = this.$updateLines.lastRow;
var layerConfig = this.layerConfig; var layerConfig = this.layerConfig;
// if the update changes the width of the document do a full redraw // if the update changes the width of the document do a full redraw
@ -393,7 +393,7 @@ var VirtualRenderer = function(container, theme) {
// else update only the changed rows // else update only the changed rows
this.$textLayer.updateLines(layerConfig, firstRow, lastRow); this.$textLayer.updateLines(layerConfig, firstRow, lastRow);
}; };
this.$getLongestLine = function() { this.$getLongestLine = function() {
var charCount = this.doc.getScreenWidth(); var charCount = this.doc.getScreenWidth();
if (this.$showInvisibles) if (this.$showInvisibles)
@ -401,7 +401,7 @@ var VirtualRenderer = function(container, theme) {
return Math.max(this.$size.scrollerWidth, Math.round(charCount * this.characterWidth)); return Math.max(this.$size.scrollerWidth, Math.round(charCount * this.characterWidth));
}; };
this.addMarker = function(range, clazz, type) { this.addMarker = function(range, clazz, type) {
return this.$markerLayer.addMarker(range, clazz, type); return this.$markerLayer.addMarker(range, clazz, type);
this.$loop.schedule(this.CHANGE_MARKER); this.$loop.schedule(this.CHANGE_MARKER);
@ -513,7 +513,7 @@ var VirtualRenderer = function(container, theme) {
this.hideComposition = function() { this.hideComposition = function() {
}; };
this.setTheme = function(theme) { this.setTheme = function(theme) {
var _self = this; var _self = this;
if (!theme || typeof theme == "string") { if (!theme || typeof theme == "string") {
@ -524,17 +524,17 @@ var VirtualRenderer = function(container, theme) {
} else { } else {
afterLoad(theme); afterLoad(theme);
} }
var _self = this; 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)
_self.$theme = theme ? theme.cssClass : null; _self.$theme = theme ? theme.cssClass : null;
if (_self.$theme) if (_self.$theme)
dom.addCssClass(_self.container, _self.$theme) dom.addCssClass(_self.container, _self.$theme)
// force remeasure of the gutter width // force remeasure of the gutter width
if (_self.$size) { if (_self.$size) {
_self.$size.width = 0; _self.$size.width = 0;