Merge branch 'master' of github.com:ajaxorg/editor
Conflicts: src/ace/lib/lang.js
This commit is contained in:
commit
6dd64b8117
7 changed files with 104 additions and 24 deletions
|
|
@ -21,12 +21,12 @@ var BackgroundTokenizer = function(tokenizer) {
|
|||
self.lines[self.currentLine] = self.$tokenizeRow(self.currentLine);
|
||||
self.currentLine++;
|
||||
|
||||
// only check every 30 lines
|
||||
// only check every 5 lines
|
||||
processedLines += 1;
|
||||
if ((processedLines % 30 == 0) && (new Date() - workerStart) > 20) {
|
||||
//if ((processedLines % 5 == 0) && (new Date() - workerStart) > 20) {
|
||||
self.fireUpdateEvent(startLine, self.currentLine-1);
|
||||
return setTimeout(self.$worker, 10);
|
||||
}
|
||||
return setTimeout(self.$worker, 0);
|
||||
//}
|
||||
}
|
||||
|
||||
self.running = false;
|
||||
|
|
@ -67,11 +67,9 @@ var BackgroundTokenizer = function(tokenizer) {
|
|||
|
||||
this.lines.splice(this.currentLine, this.lines.length);
|
||||
|
||||
if (!this.running) {
|
||||
clearTimeout(this.running);
|
||||
// pretty long delay to prevent the tokenizer from interfering with the user
|
||||
this.running = setTimeout(this.$worker, 200);
|
||||
}
|
||||
this.stop();
|
||||
// pretty long delay to prevent the tokenizer from interfering with the user
|
||||
this.running = setTimeout(this.$worker, 200);
|
||||
};
|
||||
|
||||
this.stop = function() {
|
||||
|
|
|
|||
|
|
@ -323,8 +323,7 @@ var Editor = function(renderer, doc) {
|
|||
};
|
||||
|
||||
this.onMouseWheel = function(e) {
|
||||
var delta = e.wheel;
|
||||
this.renderer.scrollToY(this.renderer.getScrollTop() - (delta * 15));
|
||||
this.renderer.scrollBy(e.wheelX, e.wheelY);
|
||||
return ace.preventDefault(e);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
this.$options = {
|
||||
|
|
@ -139,10 +141,8 @@ Search.SELECTION = 2;
|
|||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
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() {
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ var VirtualRenderer = function(container) {
|
|||
this.$textLayer.updateLines(layerConfig, firstRow, lastRow);
|
||||
};
|
||||
|
||||
this.draw = function() {
|
||||
this.draw = function(scrollOnly) {
|
||||
var lines = this.lines;
|
||||
|
||||
var offset = this.scrollTop % this.lineHeight;
|
||||
|
|
@ -216,7 +216,8 @@ var VirtualRenderer = function(container) {
|
|||
lastRow : lastRow,
|
||||
lineHeight : this.lineHeight,
|
||||
characterWidth : this.characterWidth,
|
||||
minHeight : minHeight
|
||||
minHeight : minHeight,
|
||||
scrollOnly: !!scrollOnly
|
||||
};
|
||||
|
||||
this.content.style.marginTop = (-offset) + "px";
|
||||
|
|
@ -309,10 +310,15 @@ var VirtualRenderer = function(container) {
|
|||
if (this.scrollTop !== scrollTop) {
|
||||
this.scrollTop = scrollTop;
|
||||
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) {
|
||||
var canvasPos = this.scroller.getBoundingClientRect();
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
if (!config.minHeight)
|
||||
return;
|
||||
|
||||
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 = [];
|
||||
for ( var i = config.firstRow; i <= config.lastRow; i++) {
|
||||
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>");
|
||||
}
|
||||
|
||||
|
|
@ -137,7 +198,7 @@ var Text = function(parentEl) {
|
|||
"rparen": true,
|
||||
"lparen": true
|
||||
};
|
||||
|
||||
|
||||
this.renderLine = function(stringBuilder, row) {
|
||||
var tokens = this.tokenizer.getTokens(row);
|
||||
|
||||
|
|
|
|||
|
|
@ -110,8 +110,24 @@ require.def("ace/lib/event", ["ace/lib/core"], function(core) {
|
|||
|
||||
event.addMouseWheelListener = function(el, callback) {
|
||||
var listener = function(e) {
|
||||
e.wheel = (e.wheelDelta) ? e.wheelDelta / 120
|
||||
: -(e.detail || 0) / 3;
|
||||
if (e.wheelDelta !== undefined) {
|
||||
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);
|
||||
};
|
||||
event.addListener(el, "DOMMouseScroll", listener);
|
||||
|
|
@ -158,6 +174,6 @@ require.def("ace/lib/event", ["ace/lib/core"], function(core) {
|
|||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return event;
|
||||
});
|
||||
|
|
@ -43,7 +43,7 @@ require.def("ace/lib/lang", function() {
|
|||
|
||||
};
|
||||
|
||||
this.escapeRegExp = function(str) {
|
||||
lang.escapeRegExp = function(str) {
|
||||
return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue