Merge branch 'master' of github.com:ajaxorg/editor

Conflicts:
	src/ace/lib/lang.js
This commit is contained in:
mikedeboer 2010-09-20 14:08:40 +02:00
commit 6dd64b8117
7 changed files with 104 additions and 24 deletions

View file

@ -21,12 +21,12 @@ var BackgroundTokenizer = function(tokenizer) {
self.lines[self.currentLine] = self.$tokenizeRow(self.currentLine); self.lines[self.currentLine] = self.$tokenizeRow(self.currentLine);
self.currentLine++; self.currentLine++;
// only check every 30 lines // only check every 5 lines
processedLines += 1; processedLines += 1;
if ((processedLines % 30 == 0) && (new Date() - workerStart) > 20) { //if ((processedLines % 5 == 0) && (new Date() - workerStart) > 20) {
self.fireUpdateEvent(startLine, self.currentLine-1); self.fireUpdateEvent(startLine, self.currentLine-1);
return setTimeout(self.$worker, 10); return setTimeout(self.$worker, 0);
} //}
} }
self.running = false; self.running = false;
@ -67,11 +67,9 @@ var BackgroundTokenizer = function(tokenizer) {
this.lines.splice(this.currentLine, this.lines.length); this.lines.splice(this.currentLine, this.lines.length);
if (!this.running) { this.stop();
clearTimeout(this.running); // pretty long delay to prevent the tokenizer from interfering with the user
// pretty long delay to prevent the tokenizer from interfering with the user this.running = setTimeout(this.$worker, 200);
this.running = setTimeout(this.$worker, 200);
}
}; };
this.stop = function() { this.stop = function() {

View file

@ -323,8 +323,7 @@ var Editor = function(renderer, doc) {
}; };
this.onMouseWheel = function(e) { this.onMouseWheel = function(e) {
var delta = e.wheel; this.renderer.scrollBy(e.wheelX, e.wheelY);
this.renderer.scrollToY(this.renderer.getScrollTop() - (delta * 15));
return ace.preventDefault(e); return ace.preventDefault(e);
}; };

View file

@ -1,4 +1,6 @@
require.def("ace/Search", ["ace/ace"], function(ace) { require.def("ace/Search",
["ace/ace", "ace/Range"],
function(ace, Range) {
var Search = function() { var Search = function() {
this.$options = { this.$options = {
@ -139,10 +141,8 @@ Search.SELECTION = 2;
}; };
}; };
this.$rangeFromMatch = function(row, column, length) { this.$rangeFromMatch = function(row, column, length) {
return new ace.Range(row, column, row, column+length); return new Range(row, column, row, column+length);
}; };
this.$assembleRegExp = function() { this.$assembleRegExp = function() {

View file

@ -194,7 +194,7 @@ var VirtualRenderer = function(container) {
this.$textLayer.updateLines(layerConfig, firstRow, lastRow); this.$textLayer.updateLines(layerConfig, firstRow, lastRow);
}; };
this.draw = function() { this.draw = function(scrollOnly) {
var lines = this.lines; var lines = this.lines;
var offset = this.scrollTop % this.lineHeight; var offset = this.scrollTop % this.lineHeight;
@ -216,7 +216,8 @@ var VirtualRenderer = function(container) {
lastRow : lastRow, lastRow : lastRow,
lineHeight : this.lineHeight, lineHeight : this.lineHeight,
characterWidth : this.characterWidth, characterWidth : this.characterWidth,
minHeight : minHeight minHeight : minHeight,
scrollOnly: !!scrollOnly
}; };
this.content.style.marginTop = (-offset) + "px"; this.content.style.marginTop = (-offset) + "px";
@ -309,10 +310,15 @@ var VirtualRenderer = function(container) {
if (this.scrollTop !== scrollTop) { if (this.scrollTop !== scrollTop) {
this.scrollTop = scrollTop; this.scrollTop = scrollTop;
this.$updateScrollBar(); this.$updateScrollBar();
this.draw(); this.draw(true);
} }
}; };
this.scrollBy = function(deltaX, deltaY) {
deltaY && this.scrollToY(this.scrollTop + deltaY);
deltaX && (this.scroller.scrollLeft += deltaX);
};
this.screenToTextCoordinates = function(pageX, pageY) { this.screenToTextCoordinates = function(pageX, pageY) {
var canvasPos = this.scroller.getBoundingClientRect(); var canvasPos = this.scroller.getBoundingClientRect();

View file

@ -119,13 +119,74 @@ var Text = function(parentEl) {
}; };
}; };
this.$scrollLines = function(oldConfig, config) {
if (oldConfig.lastRow < config.firstRow)
return this.$fullUpdate(config);
if (config.lastRow < oldConfig.firstRow)
return this.$fullUpdate(config);
var el = this.element;
if (oldConfig.firstRow < config.firstRow)
for (var row=oldConfig.firstRow; row<config.firstRow; row++)
el.removeChild(el.firstChild);
if (oldConfig.lastRow > config.lastRow)
for (var row=config.lastRow+1; row<=oldConfig.lastRow; row++)
el.removeChild(el.lastChild);
if (config.firstRow < oldConfig.firstRow) {
var fragment = this.$renderLinesFragment(config, config.firstRow, oldConfig.firstRow - 1);
if (el.firstChild)
el.insertBefore(fragment, el.firstChild);
else
el.appendChild(fragment);
}
if (config.lastRow > oldConfig.lastRow) {
var fragment = this.$renderLinesFragment(config, oldConfig.lastRow + 1, config.lastRow);
el.appendChild(fragment);
}
};
this.$renderLinesFragment = function(config, firstRow, lastRow) {
var fragment = document.createDocumentFragment();
for (var row=firstRow; row<=lastRow; row++) {
var lineEl = document.createElement("div");
lineEl.className = "ace_line";
var style = lineEl.style;
style.height = this.$characterSize.height + "px";
style.width = config.width + "px";
var html = [];
this.renderLine(html, row);
lineEl.innerHTML = html.join("");
fragment.appendChild(lineEl);
}
return fragment;
};
this.update = function(config) { this.update = function(config) {
if (!config.minHeight)
return;
this.$computeTabString(); this.$computeTabString();
if (this.config && config.scrollOnly) {
this.$scrollLines(this.config, config);
} else {
this.$fullUpdate(config);
}
this.config = config;
};
this.$fullUpdate = function(config) {
var html = []; var html = [];
for ( var i = config.firstRow; i <= config.lastRow; i++) { for ( var i = config.firstRow; i <= config.lastRow; i++) {
html.push("<div class='ace_line' style='height:" + this.$characterSize.height + "px;", "width:", html.push("<div class='ace_line' style='height:" + this.$characterSize.height + "px;", "width:",
config.width, "px'>"); config.width, "px'>");
this.renderLine(html, i), html.push("</div>"); this.renderLine(html, i), html.push("</div>");
} }
@ -137,7 +198,7 @@ var Text = function(parentEl) {
"rparen": true, "rparen": true,
"lparen": true "lparen": true
}; };
this.renderLine = function(stringBuilder, row) { this.renderLine = function(stringBuilder, row) {
var tokens = this.tokenizer.getTokens(row); var tokens = this.tokenizer.getTokens(row);

View file

@ -110,8 +110,24 @@ require.def("ace/lib/event", ["ace/lib/core"], function(core) {
event.addMouseWheelListener = function(el, callback) { event.addMouseWheelListener = function(el, callback) {
var listener = function(e) { var listener = function(e) {
e.wheel = (e.wheelDelta) ? e.wheelDelta / 120 if (e.wheelDelta !== undefined) {
: -(e.detail || 0) / 3; if (e.wheelDeltaX !== undefined) {
e.wheelX = e.wheelDeltaX / 8;
e.wheelY = e.wheelDeltaY / 8;
} else {
e.wheelX = 0;
e.wheelY = e.wheelDelta / 8;
}
}
else {
if (e.axis && e.axis == e.HORIZONTAL_AXIS) {
e.wheelX = (e.detail || 0) * 5;
e.wheelY = 0;
} else {
e.wheelX = 0;
e.wheelY = (e.detail || 0) * 5;
}
}
callback(e); callback(e);
}; };
event.addListener(el, "DOMMouseScroll", listener); event.addListener(el, "DOMMouseScroll", listener);
@ -158,6 +174,6 @@ require.def("ace/lib/event", ["ace/lib/core"], function(core) {
}); });
} }
}; };
return event; return event;
}); });

View file

@ -43,7 +43,7 @@ require.def("ace/lib/lang", function() {
}; };
this.escapeRegExp = function(str) { lang.escapeRegExp = function(str) {
return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1'); return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
}; };