Merge branch 'multiCursor'

Conflicts:
	demo/kitchen-sink/demo.js
	lib/ace/test/all_browser.js
This commit is contained in:
Fabian Jakobs 2012-04-12 16:03:24 +02:00
commit aed7ca654c
26 changed files with 1902 additions and 386 deletions

View file

@ -47,11 +47,10 @@ var Cursor = function(parentEl) {
this.element.className = "ace_layer ace_cursor-layer";
parentEl.appendChild(this.element);
this.cursor = dom.createElement("div");
this.cursor.className = "ace_cursor ace_hidden";
this.element.appendChild(this.cursor);
this.isVisible = false;
this.cursors = [];
this.cursor = this.addCursor();
};
(function() {
@ -65,30 +64,54 @@ var Cursor = function(parentEl) {
this.session = session;
};
this.addCursor = function() {
var el = dom.createElement("div");
var className = "ace_cursor";
if (!this.isVisible)
className += " ace_hidden";
if (this.overwrite)
className += " ace_overwrite";
el.className = className;
this.element.appendChild(el);
this.cursors.push(el);
return el;
};
this.removeCursor = function() {
if (this.cursors.length > 1) {
var el = this.cursors.pop();
el.parentNode.removeChild(el);
return el;
}
};
this.hideCursor = function() {
this.isVisible = false;
dom.addCssClass(this.cursor, "ace_hidden");
for (var i = this.cursors.length; i--; )
dom.addCssClass(this.cursors[i], "ace_hidden");
clearInterval(this.blinkId);
};
this.showCursor = function() {
this.isVisible = true;
dom.removeCssClass(this.cursor, "ace_hidden");
this.cursor.style.visibility = "visible";
for (var i = this.cursors.length; i--; )
dom.removeCssClass(this.cursors[i], "ace_hidden");
this.element.style.visibility = "";
this.restartTimer();
};
this.restartTimer = function() {
clearInterval(this.blinkId);
if (!this.isVisible) {
if (!this.isVisible)
return;
}
var cursor = this.cursor;
var element = this.element;
this.blinkId = setInterval(function() {
cursor.style.visibility = "hidden";
element.style.visibility = "hidden";
setTimeout(function() {
cursor.style.visibility = "visible";
element.style.visibility = "visible";
}, 400);
}, 1000);
};
@ -118,25 +141,53 @@ var Cursor = function(parentEl) {
this.update = function(config) {
this.config = config;
this.pixelPos = this.getPixelPosition(null, true);
if (this.session.selectionMarkerCount > 1) {
var selections = this.session.$selectionMarkers;
var i = 0, sel, cursorIndex = 0;
this.cursor.style.left = this.pixelPos.left + "px";
this.cursor.style.top = this.pixelPos.top + "px";
this.cursor.style.width = config.characterWidth + "px";
this.cursor.style.height = config.lineHeight + "px";
for (var i = selections.length; i--; ) {
sel = selections[i];
var pixelPos = this.getPixelPosition(sel.cursor, true);
var overwrite = this.session.getOverwrite()
if (overwrite != this.overwrite) {
this.overwrite = overwrite;
if (overwrite)
dom.addCssClass(this.cursor, "ace_overwrite");
else
dom.removeCssClass(this.cursor, "ace_overwrite");
var style = (this.cursors[cursorIndex++] || this.addCursor()).style;
style.left = pixelPos.left + "px";
style.top = pixelPos.top + "px";
style.width = config.characterWidth + "px";
style.height = config.lineHeight + "px";
}
if (cursorIndex > 1)
while (this.cursors.length > cursorIndex)
this.removeCursor();
} else {
var pixelPos = this.getPixelPosition(null, true);
var style = this.cursor.style;
style.left = pixelPos.left + "px";
style.top = pixelPos.top + "px";
style.width = config.characterWidth + "px";
style.height = config.lineHeight + "px";
while (this.cursors.length > 1)
this.removeCursor();
}
var overwrite = this.session.getOverwrite();
if (overwrite != this.overwrite)
this.$setOverite(overwrite);
this.restartTimer();
};
this.$setOverite = function(overwrite) {
this.overwrite = overwrite;
for (var i = this.cursors.length; i--; ) {
if (overwrite)
dom.addCssClass(this.cursors[i], "ace_overwrite");
else
dom.removeCssClass(this.cursors[i], "ace_overwrite");
}
};
this.destroy = function() {
clearInterval(this.blinkId);
}

View file

@ -112,7 +112,7 @@ var Marker = function(parentEl) {
};
/**
* Draws a marker, which spans a range of text in a single line
* Draws a marker, which spans a range of text on multiple lines
*/
this.drawTextMarker = function(stringBuilder, range, clazz, layerConfig) {
// selection start
@ -187,7 +187,7 @@ var Marker = function(parentEl) {
};
/**
* Draws a marker which covers one single full line
* Draws a marker which covers part or whole width of a single screen line
*/
this.drawSingleLineMarker = function(stringBuilder, range, clazz, layerConfig, extraLength, type) {
var padding = type === "background" ? 0 : this.$padding;

View file

@ -302,16 +302,16 @@ var Text = function(parentEl) {
};
this.$renderLinesFragment = function(config, firstRow, lastRow) {
var fragment = this.element.ownerDocument.createDocumentFragment(),
row = firstRow,
fold = this.session.getNextFoldLine(row),
foldStart = fold ?fold.start.row :Infinity;
var fragment = this.element.ownerDocument.createDocumentFragment();
var row = firstRow;
var foldLine = this.session.getNextFoldLine(row);
var foldStart = foldLine ? foldLine.start.row : Infinity;
while (true) {
if (row > foldStart) {
row = fold.end.row+1;
fold = this.session.getNextFoldLine(row, fold);
foldStart = fold ?fold.start.row :Infinity;
row = foldLine.end.row+1;
foldLine = this.session.getNextFoldLine(row, foldLine);
foldStart = foldLine ? foldLine.start.row : Infinity;
}
if (row > lastRow)
break;
@ -350,15 +350,15 @@ var Text = function(parentEl) {
var html = [];
var firstRow = config.firstRow, lastRow = config.lastRow;
var row = firstRow,
fold = this.session.getNextFoldLine(row),
foldStart = fold ?fold.start.row :Infinity;
var row = firstRow;
var foldLine = this.session.getNextFoldLine(row);
var foldStart = foldLine ? foldLine.start.row : Infinity;
while (true) {
if (row > foldStart) {
row = fold.end.row+1;
fold = this.session.getNextFoldLine(row, fold);
foldStart = fold ?fold.start.row :Infinity;
row = foldLine.end.row+1;
foldLine = this.session.getNextFoldLine(row, foldLine);
foldStart = foldLine ? foldLine.start.row :Infinity;
}
if (row > lastRow)
break;