adapt better to ajax.org coding styles
This commit is contained in:
parent
2b88ca2c71
commit
8fe20516d4
13 changed files with 1556 additions and 1645 deletions
|
|
@ -1,22 +1,21 @@
|
||||||
if (!window.ace) ace = {};
|
if (!window.ace)
|
||||||
|
ace = {};
|
||||||
|
|
||||||
ace.BackgroundTokenizer = function(tokenizer, onUpdate, onComplete)
|
ace.BackgroundTokenizer = function(tokenizer, onUpdate, onComplete) {
|
||||||
{
|
|
||||||
this.running = false;
|
this.running = false;
|
||||||
this.textLines = [];
|
this.textLines = [];
|
||||||
this.lines = [];
|
this.lines = [];
|
||||||
this.currentLine = 0;
|
this.currentLine = 0;
|
||||||
this.tokenizer = tokenizer;
|
this.tokenizer = tokenizer;
|
||||||
|
|
||||||
this.onUpdate = onUpdate || function(firstLine, lastLine) {};
|
this.onUpdate = onUpdate || function(firstLine, lastLine) {
|
||||||
this.onComplete = onComplete || function() {};
|
};
|
||||||
|
this.onComplete = onComplete || function() {
|
||||||
|
};
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
this._worker = function()
|
this._worker = function() {
|
||||||
{
|
if (!self.running) { return; }
|
||||||
if (!self.running) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var workerStart = new Date();
|
var workerStart = new Date();
|
||||||
var startLine = self.currentLine;
|
var startLine = self.currentLine;
|
||||||
|
|
@ -24,17 +23,17 @@ ace.BackgroundTokenizer = function(tokenizer, onUpdate, onComplete)
|
||||||
|
|
||||||
var processedLines = 0;
|
var processedLines = 0;
|
||||||
|
|
||||||
while (self.currentLine < textLines.length)
|
while (self.currentLine < textLines.length) {
|
||||||
{
|
|
||||||
var line = textLines[self.currentLine];
|
var line = textLines[self.currentLine];
|
||||||
|
|
||||||
var state = self.currentLine == 0 ? "start" : self.lines[self.currentLine-1].state;
|
var state = self.currentLine == 0 ? "start"
|
||||||
self.lines[self.currentLine] = self.tokenizer.getLineTokens(line, state);
|
: self.lines[self.currentLine - 1].state;
|
||||||
|
self.lines[self.currentLine] = self.tokenizer.getLineTokens(line,
|
||||||
|
state);
|
||||||
|
|
||||||
// only check every 30 lines
|
// only check every 30 lines
|
||||||
processedLines += 1;
|
processedLines += 1;
|
||||||
if ((processedLines % 30 == 0) && (new Date()-workerStart) > 20)
|
if ((processedLines % 30 == 0) && (new Date() - workerStart) > 20) {
|
||||||
{
|
|
||||||
self.onUpdate(startLine, self.currentLine);
|
self.onUpdate(startLine, self.currentLine);
|
||||||
return setTimeout(self._worker, 10);
|
return setTimeout(self._worker, 10);
|
||||||
}
|
}
|
||||||
|
|
@ -44,26 +43,24 @@ ace.BackgroundTokenizer = function(tokenizer, onUpdate, onComplete)
|
||||||
|
|
||||||
self.running = false;
|
self.running = false;
|
||||||
|
|
||||||
self.onUpdate(startLine, textLines.length-1);
|
self.onUpdate(startLine, textLines.length - 1);
|
||||||
self.onComplete();
|
self.onComplete();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.BackgroundTokenizer.prototype.setLines = function(textLines)
|
ace.BackgroundTokenizer.prototype.setLines = function(textLines) {
|
||||||
{
|
|
||||||
this.textLines = textLines;
|
this.textLines = textLines;
|
||||||
this.lines = [];
|
this.lines = [];
|
||||||
|
|
||||||
this.stop();
|
this.stop();
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.BackgroundTokenizer.prototype.start = function(startRow)
|
ace.BackgroundTokenizer.prototype.start = function(startRow) {
|
||||||
{
|
this.currentLine = Math.min(startRow || 0, this.currentLine,
|
||||||
this.currentLine = Math.min(startRow || 0, this.currentLine, this.textLines.length);
|
this.textLines.length);
|
||||||
this.lines.splice(startRow, this.lines.length);
|
this.lines.splice(startRow, this.lines.length);
|
||||||
|
|
||||||
if (!this.running)
|
if (!this.running) {
|
||||||
{
|
|
||||||
this.running = true;
|
this.running = true;
|
||||||
setTimeout(this._worker, 50);
|
setTimeout(this._worker, 50);
|
||||||
}
|
}
|
||||||
|
|
@ -73,14 +70,14 @@ ace.BackgroundTokenizer.prototype.stop = function() {
|
||||||
this.running = false;
|
this.running = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.BackgroundTokenizer.prototype.getTokens = function(row)
|
ace.BackgroundTokenizer.prototype.getTokens = function(row) {
|
||||||
{
|
|
||||||
if (this.lines[row]) {
|
if (this.lines[row]) {
|
||||||
return this.lines[row].tokens;
|
return this.lines[row].tokens;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
var state = "start";
|
var state = "start";
|
||||||
if (row > 0 && this.lines[row-1]) {
|
if (row > 0 && this.lines[row - 1]) {
|
||||||
state = this.lines[row-1].state;
|
state = this.lines[row - 1].state;
|
||||||
}
|
}
|
||||||
return this.tokenizer.getLineTokens(this.textLines[row] || "", state).tokens;
|
return this.tokenizer.getLineTokens(this.textLines[row] || "", state).tokens;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
if (!window.ace) ace = {};
|
if (!window.ace)
|
||||||
|
ace = {};
|
||||||
|
|
||||||
ace.CursorLayer = function(parentEl)
|
ace.CursorLayer = function(parentEl) {
|
||||||
{
|
|
||||||
this.element = document.createElement("div");
|
this.element = document.createElement("div");
|
||||||
this.element.className = "layer cursor-layer";
|
this.element.className = "layer cursor-layer";
|
||||||
parentEl.appendChild(this.element);
|
parentEl.appendChild(this.element);
|
||||||
|
|
@ -12,16 +12,14 @@ ace.CursorLayer = function(parentEl)
|
||||||
this.isVisible = false;
|
this.isVisible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ace.CursorLayer.prototype.setCursor = function(position)
|
ace.CursorLayer.prototype.setCursor = function(position) {
|
||||||
{
|
|
||||||
this.position = {
|
this.position = {
|
||||||
row: position.row,
|
row : position.row,
|
||||||
column: position.column
|
column : position.column
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.CursorLayer.prototype.hideCursor = function()
|
ace.CursorLayer.prototype.hideCursor = function() {
|
||||||
{
|
|
||||||
this.isVisible = false;
|
this.isVisible = false;
|
||||||
if (this.cursor.parentNode) {
|
if (this.cursor.parentNode) {
|
||||||
this.cursor.parentNode.removeChild(this.cursor);
|
this.cursor.parentNode.removeChild(this.cursor);
|
||||||
|
|
@ -29,8 +27,7 @@ ace.CursorLayer.prototype.hideCursor = function()
|
||||||
clearInterval(this.blinkId);
|
clearInterval(this.blinkId);
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.CursorLayer.prototype.showCursor = function()
|
ace.CursorLayer.prototype.showCursor = function() {
|
||||||
{
|
|
||||||
this.isVisible = true;
|
this.isVisible = true;
|
||||||
this.element.appendChild(this.cursor);
|
this.element.appendChild(this.cursor);
|
||||||
|
|
||||||
|
|
@ -46,23 +43,27 @@ ace.CursorLayer.prototype.showCursor = function()
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.CursorLayer.prototype.getPixelPosition = function() {
|
ace.CursorLayer.prototype.getPixelPosition = function() {
|
||||||
return this.pixelPos || {left: 0, top:0};
|
return this.pixelPos || {
|
||||||
|
left : 0,
|
||||||
|
top : 0
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
ace.CursorLayer.prototype.update = function(config)
|
ace.CursorLayer.prototype.update = function(config) {
|
||||||
{
|
if (!this.position)
|
||||||
if (!this.position) return;
|
return;
|
||||||
|
|
||||||
var cursorLeft = Math.round(this.position.column * config.characterWidth);
|
var cursorLeft = Math.round(this.position.column * config.characterWidth);
|
||||||
var cursorTop = this.position.row * config.lineHeight;
|
var cursorTop = this.position.row * config.lineHeight;
|
||||||
|
|
||||||
this.pixelPos = {
|
this.pixelPos = {
|
||||||
left: cursorLeft,
|
left : cursorLeft,
|
||||||
top: cursorTop
|
top : cursorTop
|
||||||
};
|
};
|
||||||
|
|
||||||
this.cursor.style.left = cursorLeft + "px";
|
this.cursor.style.left = cursorLeft + "px";
|
||||||
this.cursor.style.top = (cursorTop - (config.firstRow * config.lineHeight)) + "px";
|
this.cursor.style.top = (cursorTop - (config.firstRow * config.lineHeight))
|
||||||
|
+ "px";
|
||||||
this.cursor.style.height = config.lineHeight + "px";
|
this.cursor.style.height = config.lineHeight + "px";
|
||||||
|
|
||||||
if (this.isVisible) {
|
if (this.isVisible) {
|
||||||
|
|
|
||||||
349
src/Editor.js
349
src/Editor.js
|
|
@ -1,33 +1,30 @@
|
||||||
if (!window.ace) ace = {};
|
if (!window.ace)
|
||||||
|
ace = {};
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
var keys = {
|
var keys = {
|
||||||
UP: 38,
|
UP : 38,
|
||||||
RIGHT: 39,
|
RIGHT : 39,
|
||||||
DOWN: 40,
|
DOWN : 40,
|
||||||
LEFT: 37,
|
LEFT : 37,
|
||||||
PAGEUP: 33,
|
PAGEUP : 33,
|
||||||
PAGEDOWN: 34,
|
PAGEDOWN : 34,
|
||||||
POS1: 36,
|
POS1 : 36,
|
||||||
END: 35,
|
END : 35,
|
||||||
DELETE: 46,
|
DELETE : 46,
|
||||||
BACKSPACE: 8,
|
BACKSPACE : 8,
|
||||||
TAB: 9,
|
TAB : 9,
|
||||||
A: 65
|
A : 65
|
||||||
}
|
}
|
||||||
|
|
||||||
var KeyBinding = function(element, host)
|
var KeyBinding = function(element, host) {
|
||||||
{
|
ace.addListener(element, "keydown", function(e) {
|
||||||
ace.addListener(element, "keydown", function(e)
|
|
||||||
{
|
|
||||||
var key = e.keyCode;
|
var key = e.keyCode;
|
||||||
|
|
||||||
switch (key)
|
switch (key) {
|
||||||
{
|
|
||||||
case keys.A:
|
case keys.A:
|
||||||
if (e.metaKey)
|
if (e.metaKey) {
|
||||||
{
|
|
||||||
host.selectAll();
|
host.selectAll();
|
||||||
return ace.stopEvent(e);
|
return ace.stopEvent(e);
|
||||||
}
|
}
|
||||||
|
|
@ -36,9 +33,11 @@ var KeyBinding = function(element, host)
|
||||||
case keys.UP:
|
case keys.UP:
|
||||||
if (e.metaKey) {
|
if (e.metaKey) {
|
||||||
host.navigateFileStart();
|
host.navigateFileStart();
|
||||||
} if (e.shiftKey) {
|
}
|
||||||
|
if (e.shiftKey) {
|
||||||
host.selectUp();
|
host.selectUp();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
host.navigateUp();
|
host.navigateUp();
|
||||||
}
|
}
|
||||||
return ace.stopEvent(e);
|
return ace.stopEvent(e);
|
||||||
|
|
@ -46,9 +45,11 @@ var KeyBinding = function(element, host)
|
||||||
case keys.DOWN:
|
case keys.DOWN:
|
||||||
if (e.metaKey) {
|
if (e.metaKey) {
|
||||||
host.navigateFileEnd();
|
host.navigateFileEnd();
|
||||||
} if (e.shiftKey) {
|
}
|
||||||
|
if (e.shiftKey) {
|
||||||
host.selectDown();
|
host.selectDown();
|
||||||
} else{
|
}
|
||||||
|
else {
|
||||||
host.navigateDown();
|
host.navigateDown();
|
||||||
}
|
}
|
||||||
return ace.stopEvent(e);
|
return ace.stopEvent(e);
|
||||||
|
|
@ -56,11 +57,14 @@ var KeyBinding = function(element, host)
|
||||||
case keys.LEFT:
|
case keys.LEFT:
|
||||||
if (e.metaKey && e.shiftKey) {
|
if (e.metaKey && e.shiftKey) {
|
||||||
host.selectLineStart();
|
host.selectLineStart();
|
||||||
} else if (e.metaKey) {
|
}
|
||||||
|
else if (e.metaKey) {
|
||||||
host.navigateLineStart();
|
host.navigateLineStart();
|
||||||
} else if (e.shiftKey) {
|
}
|
||||||
|
else if (e.shiftKey) {
|
||||||
host.selectLeft();
|
host.selectLeft();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
host.navigateLeft();
|
host.navigateLeft();
|
||||||
}
|
}
|
||||||
return ace.stopEvent(e);
|
return ace.stopEvent(e);
|
||||||
|
|
@ -68,11 +72,14 @@ var KeyBinding = function(element, host)
|
||||||
case keys.RIGHT:
|
case keys.RIGHT:
|
||||||
if (e.metaKey && e.shiftKey) {
|
if (e.metaKey && e.shiftKey) {
|
||||||
host.selectLineEnd();
|
host.selectLineEnd();
|
||||||
} else if (e.metaKey) {
|
}
|
||||||
|
else if (e.metaKey) {
|
||||||
host.navigateLineEnd();
|
host.navigateLineEnd();
|
||||||
} else if (e.shiftKey) {
|
}
|
||||||
|
else if (e.shiftKey) {
|
||||||
host.selectRight();
|
host.selectRight();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
host.navigateRight();
|
host.navigateRight();
|
||||||
}
|
}
|
||||||
return ace.stopEvent(e);
|
return ace.stopEvent(e);
|
||||||
|
|
@ -80,7 +87,8 @@ var KeyBinding = function(element, host)
|
||||||
case keys.PAGEDOWN:
|
case keys.PAGEDOWN:
|
||||||
if (e.shiftKey) {
|
if (e.shiftKey) {
|
||||||
host.selectPageDown();
|
host.selectPageDown();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
host.scrollPageDown();
|
host.scrollPageDown();
|
||||||
}
|
}
|
||||||
return ace.stopEvent(e);
|
return ace.stopEvent(e);
|
||||||
|
|
@ -88,7 +96,8 @@ var KeyBinding = function(element, host)
|
||||||
case keys.PAGEUP:
|
case keys.PAGEUP:
|
||||||
if (e.shiftKey) {
|
if (e.shiftKey) {
|
||||||
host.selectPageUp();
|
host.selectPageUp();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
host.scrollPageUp();
|
host.scrollPageUp();
|
||||||
}
|
}
|
||||||
return ace.stopEvent(e);
|
return ace.stopEvent(e);
|
||||||
|
|
@ -96,7 +105,8 @@ var KeyBinding = function(element, host)
|
||||||
case keys.POS1:
|
case keys.POS1:
|
||||||
if (e.shiftKey) {
|
if (e.shiftKey) {
|
||||||
host.selectLineStart();
|
host.selectLineStart();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
host.navigateLineStart();
|
host.navigateLineStart();
|
||||||
}
|
}
|
||||||
return ace.stopEvent(e);
|
return ace.stopEvent(e);
|
||||||
|
|
@ -104,7 +114,8 @@ var KeyBinding = function(element, host)
|
||||||
case keys.END:
|
case keys.END:
|
||||||
if (e.shiftKey) {
|
if (e.shiftKey) {
|
||||||
host.selectLineEnd();
|
host.selectLineEnd();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
host.navigateLineEnd();
|
host.navigateLineEnd();
|
||||||
}
|
}
|
||||||
return ace.stopEvent(e);
|
return ace.stopEvent(e);
|
||||||
|
|
@ -124,34 +135,34 @@ var KeyBinding = function(element, host)
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor = function(doc, renderer)
|
ace.Editor = function(doc, renderer) {
|
||||||
{
|
|
||||||
var container = renderer.getContainerElement();
|
var container = renderer.getContainerElement();
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
|
|
||||||
this.textInput = new ace.TextInput(container, this);
|
this.textInput = new ace.TextInput(container, this);
|
||||||
new KeyBinding(container, this);
|
new KeyBinding(container, this);
|
||||||
|
|
||||||
ace.addListener(container, "mousedown", ace.bind(this.onMouseDown, this));
|
ace.addListener(container, "mousedown", ace
|
||||||
ace.addListener(container, "dblclick", ace.bind(this.onMouseDoubleClick, this));
|
.bind(this.onMouseDown, this));
|
||||||
|
ace.addListener(container, "dblclick", ace
|
||||||
|
.bind(this.onMouseDoubleClick, this));
|
||||||
ace.addMouseWheelListener(container, ace.bind(this.onMouseWheel, this));
|
ace.addMouseWheelListener(container, ace.bind(this.onMouseWheel, this));
|
||||||
ace.addTripleClickListener(container, ace.bind(this.selectCurrentLine, this));
|
ace.addTripleClickListener(container, ace.bind(this.selectCurrentLine,
|
||||||
|
this));
|
||||||
|
|
||||||
this.doc = doc;
|
this.doc = doc;
|
||||||
doc.addChangeListener(ace.bind(this.onDocumentChange, this));
|
doc.addChangeListener(ace.bind(this.onDocumentChange, this));
|
||||||
renderer.setDocument(doc);
|
renderer.setDocument(doc);
|
||||||
|
|
||||||
this.tokenizer = new ace.BackgroundTokenizer(
|
this.tokenizer = new ace.BackgroundTokenizer(new ace.Tokenizer(
|
||||||
new ace.Tokenizer(ace.XML.RULES),
|
ace.XML.RULES), ace.bind(this.onTokenizerUpdate, this));
|
||||||
ace.bind(this.onTokenizerUpdate, this)
|
|
||||||
);
|
|
||||||
|
|
||||||
this.tokenizer.setLines(doc.lines);
|
this.tokenizer.setLines(doc.lines);
|
||||||
renderer.setTokenizer(this.tokenizer);
|
renderer.setTokenizer(this.tokenizer);
|
||||||
|
|
||||||
this.cursor = {
|
this.cursor = {
|
||||||
row: 0,
|
row : 0,
|
||||||
column: 0
|
column : 0
|
||||||
};
|
};
|
||||||
|
|
||||||
this.selectionAnchor = null;
|
this.selectionAnchor = null;
|
||||||
|
|
@ -179,8 +190,7 @@ ace.Editor.prototype.onBlur = function() {
|
||||||
this.renderer.visualizeBlur();
|
this.renderer.visualizeBlur();
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.onDocumentChange = function(startRow, endRow)
|
ace.Editor.prototype.onDocumentChange = function(startRow, endRow) {
|
||||||
{
|
|
||||||
this.tokenizer.start(startRow);
|
this.tokenizer.start(startRow);
|
||||||
this.renderer.updateLines(startRow, endRow);
|
this.renderer.updateLines(startRow, endRow);
|
||||||
};
|
};
|
||||||
|
|
@ -189,8 +199,7 @@ ace.Editor.prototype.onTokenizerUpdate = function(startRow, endRow) {
|
||||||
this.renderer.updateLines(startRow, endRow);
|
this.renderer.updateLines(startRow, endRow);
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.onMouseDown = function(e)
|
ace.Editor.prototype.onMouseDown = function(e) {
|
||||||
{
|
|
||||||
this.textInput.focus();
|
this.textInput.focus();
|
||||||
|
|
||||||
var pos = this.renderer.screenToTextCoordinates(e.pageX, e.pageY);
|
var pos = this.renderer.screenToTextCoordinates(e.pageX, e.pageY);
|
||||||
|
|
@ -210,11 +219,12 @@ ace.Editor.prototype.onMouseDown = function(e)
|
||||||
clearInterval(timerId);
|
clearInterval(timerId);
|
||||||
};
|
};
|
||||||
|
|
||||||
var onSelectionInterval = function()
|
var onSelectionInterval = function() {
|
||||||
{
|
if (mousePageX === undefined || mousePageY === undefined)
|
||||||
if (mousePageX === undefined || mousePageY === undefined) return;
|
return;
|
||||||
|
|
||||||
selectionLead = _self.renderer.screenToTextCoordinates(mousePageX, mousePageY);
|
selectionLead = _self.renderer.screenToTextCoordinates(mousePageX,
|
||||||
|
mousePageY);
|
||||||
|
|
||||||
_self._moveSelection(function() {
|
_self._moveSelection(function() {
|
||||||
_self.moveCursorTo(selectionLead.row, selectionLead.column);
|
_self.moveCursorTo(selectionLead.row, selectionLead.column);
|
||||||
|
|
@ -223,13 +233,12 @@ ace.Editor.prototype.onMouseDown = function(e)
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.capture(this.container, onMouseSelection, onMouseSelectionEnd);
|
ace.capture(this.container, onMouseSelection, onMouseSelectionEnd);
|
||||||
var timerId = setInterval(onSelectionInterval, 20 );
|
var timerId = setInterval(onSelectionInterval, 20);
|
||||||
|
|
||||||
return ace.preventDefault(e);
|
return ace.preventDefault(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.onMouseDoubleClick = function(e)
|
ace.Editor.prototype.onMouseDoubleClick = function(e) {
|
||||||
{
|
|
||||||
var line = this.doc.getLine(this.cursor.row);
|
var line = this.doc.getLine(this.cursor.row);
|
||||||
var column = this.cursor.column;
|
var column = this.cursor.column;
|
||||||
|
|
||||||
|
|
@ -238,7 +247,7 @@ ace.Editor.prototype.onMouseDoubleClick = function(e)
|
||||||
|
|
||||||
var inToken = false;
|
var inToken = false;
|
||||||
if (column > 0) {
|
if (column > 0) {
|
||||||
inToken = !!line.charAt(column-1).match(tokenRe);
|
inToken = !!line.charAt(column - 1).match(tokenRe);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!inToken) {
|
if (!inToken) {
|
||||||
|
|
@ -248,11 +257,11 @@ ace.Editor.prototype.onMouseDoubleClick = function(e)
|
||||||
var re = inToken ? tokenRe : nonTokenRe;
|
var re = inToken ? tokenRe : nonTokenRe;
|
||||||
|
|
||||||
var start = column;
|
var start = column;
|
||||||
if (start > 0)
|
if (start > 0) {
|
||||||
{
|
|
||||||
do {
|
do {
|
||||||
start--;
|
start--;
|
||||||
} while (start >= 0 && line.charAt(start).match(re))
|
}
|
||||||
|
while (start >= 0 && line.charAt(start).match(re))
|
||||||
start++;
|
start++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -267,103 +276,96 @@ ace.Editor.prototype.onMouseDoubleClick = function(e)
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.onMouseWheel = function(e)
|
ace.Editor.prototype.onMouseWheel = function(e) {
|
||||||
{
|
|
||||||
var delta = e.wheel;
|
var delta = e.wheel;
|
||||||
this.renderer.scrollToY(this.renderer.getScrollTop() - (delta * 15));
|
this.renderer.scrollToY(this.renderer.getScrollTop() - (delta * 15));
|
||||||
return ace.preventDefault(e);
|
return ace.preventDefault(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.getCopyText = function()
|
ace.Editor.prototype.getCopyText = function() {
|
||||||
{
|
|
||||||
if (this.hasSelection()) {
|
if (this.hasSelection()) {
|
||||||
return this.doc.getTextRange(this.getSelectionRange());
|
return this.doc.getTextRange(this.getSelectionRange());
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.onCut = function()
|
ace.Editor.prototype.onCut = function() {
|
||||||
{
|
if (this.hasSelection()) {
|
||||||
if (this.hasSelection())
|
|
||||||
{
|
|
||||||
this.cursor = this.doc.remove(this.getSelectionRange());
|
this.cursor = this.doc.remove(this.getSelectionRange());
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
this.renderer.updateCursor(this.cursor);
|
this.renderer.updateCursor(this.cursor);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.onTextInput = function(text)
|
ace.Editor.prototype.onTextInput = function(text) {
|
||||||
{
|
if (this.hasSelection()) {
|
||||||
if (this.hasSelection())
|
|
||||||
{
|
|
||||||
this.cursor = this.doc.replace(this.getSelectionRange(), text);
|
this.cursor = this.doc.replace(this.getSelectionRange(), text);
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
this.cursor = this.doc.insert(this.cursor, text);
|
this.cursor = this.doc.insert(this.cursor, text);
|
||||||
}
|
}
|
||||||
this.renderer.updateCursor(this.cursor);
|
this.renderer.updateCursor(this.cursor);
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.removeRight = function()
|
ace.Editor.prototype.removeRight = function() {
|
||||||
{
|
if (this.hasSelection()) {
|
||||||
if (this.hasSelection())
|
|
||||||
{
|
|
||||||
this.cursor = this.doc.remove(this.getSelectionRange());
|
this.cursor = this.doc.remove(this.getSelectionRange());
|
||||||
this.renderer.updateCursor(this.cursor);
|
this.renderer.updateCursor(this.cursor);
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
var rangeEnd = {
|
var rangeEnd = {
|
||||||
row: this.cursor.row,
|
row : this.cursor.row,
|
||||||
column: this.cursor.column + 1
|
column : this.cursor.column + 1
|
||||||
}
|
}
|
||||||
if (rangeEnd.column > this.doc.getLine(this.cursor.row).length) {
|
if (rangeEnd.column > this.doc.getLine(this.cursor.row).length) {
|
||||||
rangeEnd.row += 1;
|
rangeEnd.row += 1;
|
||||||
rangeEnd.column = 0;
|
rangeEnd.column = 0;
|
||||||
}
|
}
|
||||||
this.doc.remove({start: this.cursor, end: renageEnd});
|
this.doc.remove( {
|
||||||
|
start : this.cursor,
|
||||||
|
end : renageEnd
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.removeLeft = function()
|
ace.Editor.prototype.removeLeft = function() {
|
||||||
{
|
if (this.hasSelection()) {
|
||||||
if (this.hasSelection())
|
|
||||||
{
|
|
||||||
this.cursor = this.doc.remove(this.getSelectionRange());
|
this.cursor = this.doc.remove(this.getSelectionRange());
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
if (this.cursor.row == 0 && this.cursor.column == 0) { return; }
|
||||||
if (this.cursor.row == 0 && this.cursor.column == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var rangeStart = {
|
var rangeStart = {
|
||||||
row: this.cursor.row,
|
row : this.cursor.row,
|
||||||
column: this.cursor.column + -1
|
column : this.cursor.column + -1
|
||||||
}
|
}
|
||||||
if (rangeStart.column < 0)
|
if (rangeStart.column < 0) {
|
||||||
{
|
|
||||||
rangeStart.row -= 1;
|
rangeStart.row -= 1;
|
||||||
rangeStart.column = this.doc.getLine(this.cursor.row-1).length;
|
rangeStart.column = this.doc
|
||||||
|
.getLine(this.cursor.row - 1).length;
|
||||||
}
|
}
|
||||||
this.cursor = this.doc.remove({start: rangeStart, end: this.cursor});
|
this.cursor = this.doc.remove( {
|
||||||
|
start : rangeStart,
|
||||||
|
end : this.cursor
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.renderer.updateCursor(this.cursor);
|
this.renderer.updateCursor(this.cursor);
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
},
|
},
|
||||||
|
|
||||||
ace.Editor.prototype.onCompositionStart = function()
|
ace.Editor.prototype.onCompositionStart = function() {
|
||||||
{
|
|
||||||
this.renderer.showComposition(this.cursor);
|
this.renderer.showComposition(this.cursor);
|
||||||
this.onTextInput(" ");
|
this.onTextInput(" ");
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.onCompositionUpdate = function(text) {
|
ace.Editor.prototype.onCompositionUpdate = function(text) {
|
||||||
this.renderer.setCompositionText(text);
|
this.renderer.setCompositionText(text);
|
||||||
|
|
@ -386,12 +388,11 @@ ace.Editor.prototype.getPageDownRow = function() {
|
||||||
return this.renderer.getLastVisibleRow() - 1;
|
return this.renderer.getLastVisibleRow() - 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.getPageUpRow = function()
|
ace.Editor.prototype.getPageUpRow = function() {
|
||||||
{
|
|
||||||
var firstRow = this.renderer.getFirstVisibleRow();
|
var firstRow = this.renderer.getFirstVisibleRow();
|
||||||
var lastRow = this.renderer.getLastVisibleRow();
|
var lastRow = this.renderer.getLastVisibleRow();
|
||||||
|
|
||||||
return firstRow - (lastRow-firstRow) + 1;
|
return firstRow - (lastRow - firstRow) + 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.scrollPageDown = function() {
|
ace.Editor.prototype.scrollPageDown = function() {
|
||||||
|
|
@ -406,8 +407,7 @@ ace.Editor.prototype.scrollToRow = function(row) {
|
||||||
this.renderer.scrollToRow(row);
|
this.renderer.scrollToRow(row);
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.navigateUp = function()
|
ace.Editor.prototype.navigateUp = function() {
|
||||||
{
|
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
this.moveCursorUp();
|
this.moveCursorUp();
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
|
|
@ -419,12 +419,12 @@ ace.Editor.prototype.navigateDown = function() {
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.navigateLeft = function()
|
ace.Editor.prototype.navigateLeft = function() {
|
||||||
{
|
|
||||||
if (this.hasSelection()) {
|
if (this.hasSelection()) {
|
||||||
var selectionStart = this.getSelectionRange().start;
|
var selectionStart = this.getSelectionRange().start;
|
||||||
this.moveCursorTo(selectionStart.row, selectionStart.column);
|
this.moveCursorTo(selectionStart.row, selectionStart.column);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
this.moveCursorLeft();
|
this.moveCursorLeft();
|
||||||
}
|
}
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
|
|
@ -432,12 +432,12 @@ ace.Editor.prototype.navigateLeft = function()
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.navigateRight = function()
|
ace.Editor.prototype.navigateRight = function() {
|
||||||
{
|
|
||||||
if (this.hasSelection()) {
|
if (this.hasSelection()) {
|
||||||
var selectionEnd = this.getSelectionRange().end;
|
var selectionEnd = this.getSelectionRange().end;
|
||||||
this.moveCursorTo(selectionEnd.row, selectionEnd.column);
|
this.moveCursorTo(selectionEnd.row, selectionEnd.column);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
this.moveCursorRight();
|
this.moveCursorRight();
|
||||||
}
|
}
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
|
|
@ -445,29 +445,25 @@ ace.Editor.prototype.navigateRight = function()
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
},
|
},
|
||||||
|
|
||||||
ace.Editor.prototype.navigateLineStart = function()
|
ace.Editor.prototype.navigateLineStart = function() {
|
||||||
{
|
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
this.moveCursorLineStart();
|
this.moveCursorLineStart();
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.navigateLineEnd = function()
|
ace.Editor.prototype.navigateLineEnd = function() {
|
||||||
{
|
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
this.moveCursorLineEnd();
|
this.moveCursorLineEnd();
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.navigateFileEnd = function()
|
ace.Editor.prototype.navigateFileEnd = function() {
|
||||||
{
|
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
this.moveCursorFileEnd();
|
this.moveCursorFileEnd();
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
},
|
},
|
||||||
|
|
||||||
ace.Editor.prototype.navigateFileStart = function()
|
ace.Editor.prototype.navigateFileStart = function() {
|
||||||
{
|
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
this.moveCursorFileStart();
|
this.moveCursorFileStart();
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
|
|
@ -481,24 +477,25 @@ ace.Editor.prototype.moveCursorDown = function() {
|
||||||
this.moveCursorBy(1, 0);
|
this.moveCursorBy(1, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.moveCursorLeft = function()
|
ace.Editor.prototype.moveCursorLeft = function() {
|
||||||
{
|
|
||||||
if (this.cursor.column == 0) {
|
if (this.cursor.column == 0) {
|
||||||
if (this.cursor.row > 0) {
|
if (this.cursor.row > 0) {
|
||||||
this.moveCursorTo(this.cursor.row-1, this.doc.getLine(this.cursor.row-1).length);
|
this.moveCursorTo(this.cursor.row - 1, this.doc
|
||||||
|
.getLine(this.cursor.row - 1).length);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
this.moveCursorBy(0, -1);
|
this.moveCursorBy(0, -1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.moveCursorRight = function()
|
ace.Editor.prototype.moveCursorRight = function() {
|
||||||
{
|
|
||||||
if (this.cursor.column == this.doc.getLine(this.cursor.row).length) {
|
if (this.cursor.column == this.doc.getLine(this.cursor.row).length) {
|
||||||
if (this.cursor.row < this.doc.getLength()-1) {
|
if (this.cursor.row < this.doc.getLength() - 1) {
|
||||||
this.moveCursorTo(this.cursor.row+1, 0);
|
this.moveCursorTo(this.cursor.row + 1, 0);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
this.moveCursorBy(0, 1);
|
this.moveCursorBy(0, 1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -508,7 +505,8 @@ ace.Editor.prototype.moveCursorLineStart = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.moveCursorLineEnd = function() {
|
ace.Editor.prototype.moveCursorLineEnd = function() {
|
||||||
this.moveCursorTo(this.cursor.row, this.doc.getLine(this.cursor.row).length);
|
this.moveCursorTo(this.cursor.row,
|
||||||
|
this.doc.getLine(this.cursor.row).length);
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.moveCursorFileEnd = function() {
|
ace.Editor.prototype.moveCursorFileEnd = function() {
|
||||||
|
|
@ -522,29 +520,31 @@ ace.Editor.prototype.moveCursorFileStart = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.moveCursorBy = function(rows, chars) {
|
ace.Editor.prototype.moveCursorBy = function(rows, chars) {
|
||||||
this.moveCursorTo(this.cursor.row+rows, this.cursor.column+chars);
|
this.moveCursorTo(this.cursor.row + rows, this.cursor.column + chars);
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.moveCursorTo = function(row, column)
|
ace.Editor.prototype.moveCursorTo = function(row, column) {
|
||||||
{
|
|
||||||
if (row >= this.doc.getLength()) {
|
if (row >= this.doc.getLength()) {
|
||||||
this.cursor.row = this.doc.getLength()-1;
|
this.cursor.row = this.doc.getLength() - 1;
|
||||||
this.cursor.column = this.doc.getLine(this.cursor.row).length;
|
this.cursor.column = this.doc.getLine(this.cursor.row).length;
|
||||||
} else if (row < 0) {
|
}
|
||||||
|
else if (row < 0) {
|
||||||
this.cursor.row = 0;
|
this.cursor.row = 0;
|
||||||
this.cursor.column = 0;
|
this.cursor.column = 0;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
this.cursor.row = row;
|
this.cursor.row = row;
|
||||||
this.cursor.column = Math.min(this.doc.getLine(this.cursor.row).length, Math.max(0, column));
|
this.cursor.column = Math
|
||||||
|
.min(this.doc.getLine(this.cursor.row).length, Math
|
||||||
|
.max(0, column));
|
||||||
}
|
}
|
||||||
this.updateCursor();
|
this.updateCursor();
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.getCursorPosition = function()
|
ace.Editor.prototype.getCursorPosition = function() {
|
||||||
{
|
|
||||||
return {
|
return {
|
||||||
row: this.cursor.row,
|
row : this.cursor.row,
|
||||||
column: this.cursor.column
|
column : this.cursor.column
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -552,42 +552,43 @@ ace.Editor.prototype.hasSelection = function() {
|
||||||
return !!this.selectionLead;
|
return !!this.selectionLead;
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.setSelectionAnchor = function(row, column)
|
ace.Editor.prototype.setSelectionAnchor = function(row, column) {
|
||||||
{
|
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
|
|
||||||
this.selectionAnchor = {
|
this.selectionAnchor = {
|
||||||
row: Math.min(this.doc.getLength()-1, Math.max(0, row)),
|
row : Math.min(this.doc.getLength() - 1, Math.max(0, row)),
|
||||||
column: Math.min(this.doc.getLine(this.cursor.row).length, Math.max(0, column))
|
column : Math.min(this.doc.getLine(this.cursor.row).length, Math
|
||||||
|
.max(0, column))
|
||||||
};
|
};
|
||||||
|
|
||||||
this.selectionLead = null;
|
this.selectionLead = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.getSelectionRange = function()
|
ace.Editor.prototype.getSelectionRange = function() {
|
||||||
{
|
|
||||||
var anchor = this.selectionAnchor;
|
var anchor = this.selectionAnchor;
|
||||||
var lead = this.selectionLead;
|
var lead = this.selectionLead;
|
||||||
|
|
||||||
if (!anchor) {
|
if (!anchor) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
|
||||||
if (anchor.row > lead.row || (anchor.row == lead.row && anchor.column > lead.column)) {
|
|
||||||
return {
|
|
||||||
start: lead,
|
|
||||||
end: anchor
|
|
||||||
}
|
}
|
||||||
} else {
|
else {
|
||||||
|
if (anchor.row > lead.row
|
||||||
|
|| (anchor.row == lead.row && anchor.column > lead.column)) {
|
||||||
return {
|
return {
|
||||||
start: anchor,
|
start : lead,
|
||||||
end: lead
|
end : anchor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return {
|
||||||
|
start : anchor,
|
||||||
|
end : lead
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.clearSelection = function()
|
ace.Editor.prototype.clearSelection = function() {
|
||||||
{
|
|
||||||
this.selectionLead = null;
|
this.selectionLead = null;
|
||||||
this.selectionAnchor = null;
|
this.selectionAnchor = null;
|
||||||
|
|
||||||
|
|
@ -597,9 +598,8 @@ ace.Editor.prototype.clearSelection = function()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.selectAll = function()
|
ace.Editor.prototype.selectAll = function() {
|
||||||
{
|
var lastRow = this.doc.getLength() - 1;
|
||||||
var lastRow = this.doc.getLength()-1;
|
|
||||||
this.setSelectionAnchor(lastRow, this.doc.getLine(lastRow).length);
|
this.setSelectionAnchor(lastRow, this.doc.getLine(lastRow).length);
|
||||||
|
|
||||||
this._moveSelection(function() {
|
this._moveSelection(function() {
|
||||||
|
|
@ -607,26 +607,26 @@ ace.Editor.prototype.selectAll = function()
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype._moveSelection = function(mover)
|
ace.Editor.prototype._moveSelection = function(mover) {
|
||||||
{
|
|
||||||
if (!this.selectionAnchor) {
|
if (!this.selectionAnchor) {
|
||||||
this.selectionAnchor = {
|
this.selectionAnchor = {
|
||||||
row: this.cursor.row,
|
row : this.cursor.row,
|
||||||
column: this.cursor.column
|
column : this.cursor.column
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mover.call(this);
|
mover.call(this);
|
||||||
|
|
||||||
this.selectionLead = {
|
this.selectionLead = {
|
||||||
row: this.cursor.row,
|
row : this.cursor.row,
|
||||||
column: this.cursor.column
|
column : this.cursor.column
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.selection) {
|
if (this.selection) {
|
||||||
this.renderer.removeMarker(this.selection);
|
this.renderer.removeMarker(this.selection);
|
||||||
}
|
}
|
||||||
this.selection = this.renderer.addMarker(this.getSelectionRange(), "selection");
|
this.selection = this.renderer.addMarker(this.getSelectionRange(),
|
||||||
|
"selection");
|
||||||
this.renderer.scrollCursorIntoView();
|
this.renderer.scrollCursorIntoView();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -654,8 +654,7 @@ ace.Editor.prototype.selectLineEnd = function() {
|
||||||
this._moveSelection(this.moveCursorLineEnd);
|
this._moveSelection(this.moveCursorLineEnd);
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.selectPageDown = function()
|
ace.Editor.prototype.selectPageDown = function() {
|
||||||
{
|
|
||||||
var visibleRows = this.getLastVisibleRow() - this.getFirstVisibleRow();
|
var visibleRows = this.getLastVisibleRow() - this.getFirstVisibleRow();
|
||||||
var row = this.getPageDownRow() + Math.round(visibleRows / 2);
|
var row = this.getPageDownRow() + Math.round(visibleRows / 2);
|
||||||
|
|
||||||
|
|
@ -666,8 +665,7 @@ ace.Editor.prototype.selectPageDown = function()
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.selectPageUp = function()
|
ace.Editor.prototype.selectPageUp = function() {
|
||||||
{
|
|
||||||
var visibleRows = this.getLastVisibleRow() - this.getFirstVisibleRow();
|
var visibleRows = this.getLastVisibleRow() - this.getFirstVisibleRow();
|
||||||
var row = this.getPageUpRow() + Math.round(visibleRows / 2);
|
var row = this.getPageUpRow() + Math.round(visibleRows / 2);
|
||||||
|
|
||||||
|
|
@ -678,11 +676,10 @@ ace.Editor.prototype.selectPageUp = function()
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Editor.prototype.selectCurrentLine = function()
|
ace.Editor.prototype.selectCurrentLine = function() {
|
||||||
{
|
|
||||||
this.setSelectionAnchor(this.cursor.row, 0);
|
this.setSelectionAnchor(this.cursor.row, 0);
|
||||||
this._moveSelection(function() {
|
this._moveSelection(function() {
|
||||||
this.moveCursorTo(this.cursor.row+1, 0);
|
this.moveCursorTo(this.cursor.row + 1, 0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,17 @@
|
||||||
if (!window.ace) ace = {};
|
if (!window.ace)
|
||||||
|
ace = {};
|
||||||
|
|
||||||
ace.GutterLayer = function(parentEl)
|
ace.GutterLayer = function(parentEl) {
|
||||||
{
|
|
||||||
this.element = document.createElement("div");
|
this.element = document.createElement("div");
|
||||||
this.element.className = "layer gutter-layer";
|
this.element.className = "layer gutter-layer";
|
||||||
parentEl.appendChild(this.element);
|
parentEl.appendChild(this.element);
|
||||||
}
|
}
|
||||||
|
|
||||||
ace.GutterLayer.prototype.update = function(config)
|
ace.GutterLayer.prototype.update = 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='gutter-cell' style='height:" + config.lineHeight
|
||||||
html.push(
|
+ "px;'>", i, "</div>");
|
||||||
"<div class='gutter-cell' style='height:" + config.lineHeight + "px;'>",
|
|
||||||
i,
|
|
||||||
"</div>"
|
|
||||||
);
|
|
||||||
html.push("</div>");
|
html.push("</div>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
if (!window.ace) ace = {};
|
if (!window.ace)
|
||||||
|
ace = {};
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
|
@ -34,106 +35,80 @@ var keywords = {
|
||||||
// regexps are ordered -> the first match is used
|
// regexps are ordered -> the first match is used
|
||||||
|
|
||||||
ace.JavaScript.RULES = {
|
ace.JavaScript.RULES = {
|
||||||
start :
|
start : [ {
|
||||||
[
|
token : "comment",
|
||||||
{
|
regex : "\\/\\/.*$"
|
||||||
token: "comment",
|
}, {
|
||||||
regex: "\\/\\/.*$"
|
token : "comment", // multi line comment in one line
|
||||||
},
|
regex : "\\/\\*.*?\\*\\/"
|
||||||
{
|
}, {
|
||||||
token: "comment", // multi line comment in one line
|
token : "comment", // multi line comment start
|
||||||
regex: "\\/\\*.*?\\*\\/"
|
regex : "\\/\\*.*$",
|
||||||
},
|
next : "comment"
|
||||||
{
|
}, {
|
||||||
token: "comment", // multi line comment start
|
token : "string", // single line
|
||||||
regex: "\\/\\*.*$",
|
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
|
||||||
next: "comment"
|
}, {
|
||||||
},
|
token : "string", // multi line string start
|
||||||
{
|
regex : '["].*\\\\$',
|
||||||
token: "string", // single line
|
next : "qqstring"
|
||||||
regex: '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
|
}, {
|
||||||
},
|
token : "string", // single line
|
||||||
{
|
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
|
||||||
token: "string", // multi line string start
|
}, {
|
||||||
regex: '["].*\\\\$',
|
token : "string", // multi line string start
|
||||||
next: "qqstring"
|
regex : "['].*\\\\$",
|
||||||
},
|
next : "qstring"
|
||||||
{
|
}, {
|
||||||
token: "string", // single line
|
token : "number", // hex
|
||||||
regex: "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
|
regex : "0[xX][0-9a-fA-F]+\\b"
|
||||||
},
|
}, {
|
||||||
{
|
token : "number", // float
|
||||||
token: "string", // multi line string start
|
regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
|
||||||
regex: "['].*\\\\$",
|
}, {
|
||||||
next: "qstring"
|
token : function(value) {
|
||||||
},
|
|
||||||
{
|
|
||||||
token: "number", // hex
|
|
||||||
regex: "0[xX][0-9a-fA-F]+\\b"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
token: "number", // float
|
|
||||||
regex: "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
token: function(value)
|
|
||||||
{
|
|
||||||
if (keywords[value]) {
|
if (keywords[value]) {
|
||||||
return "keyword";
|
return "keyword";
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return "identifier"
|
return "identifier"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
regex: "[a-zA-Z_][a-zA-Z0-9_]*\\b"
|
regex : "[a-zA-Z_][a-zA-Z0-9_]*\\b"
|
||||||
},
|
}, {
|
||||||
{
|
token : function(value) {
|
||||||
token: function(value) {
|
// return parens[value];
|
||||||
//return parens[value];
|
|
||||||
return "text";
|
return "text";
|
||||||
},
|
},
|
||||||
regex: "[\\[\\]\\(\\)\\{\\}]"
|
regex : "[\\[\\]\\(\\)\\{\\}]"
|
||||||
},
|
}, {
|
||||||
{
|
token : "text",
|
||||||
token: "text",
|
regex : "\\s+"
|
||||||
regex: "\\s+"
|
} ],
|
||||||
}
|
"comment" : [ {
|
||||||
],
|
token : "comment", // closing comment
|
||||||
"comment":
|
regex : ".*?\\*\\/",
|
||||||
[
|
next : "start"
|
||||||
{
|
}, {
|
||||||
token: "comment", // closing comment
|
token : "comment", // comment spanning whole line
|
||||||
regex: ".*?\\*\\/",
|
regex : ".+"
|
||||||
next: "start"
|
} ],
|
||||||
},
|
"qqstring" : [ {
|
||||||
{
|
token : "string",
|
||||||
token: "comment", // comment spanning whole line
|
regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
|
||||||
regex: ".+"
|
next : "start"
|
||||||
}
|
}, {
|
||||||
],
|
token : "string",
|
||||||
"qqstring":
|
regex : '.+'
|
||||||
[
|
} ],
|
||||||
{
|
"qstring" : [ {
|
||||||
token: "string",
|
token : "string",
|
||||||
regex: '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
|
regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
|
||||||
next: "start"
|
next : "start"
|
||||||
},
|
}, {
|
||||||
{
|
token : "string",
|
||||||
token: "string",
|
regex : '.+'
|
||||||
regex: '.+'
|
} ]
|
||||||
}
|
|
||||||
],
|
|
||||||
"qstring":
|
|
||||||
[
|
|
||||||
{
|
|
||||||
token: "string",
|
|
||||||
regex: "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
|
|
||||||
next: "start"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
token: "string",
|
|
||||||
regex: '.+'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
if (!window.ace) ace = {};
|
if (!window.ace)
|
||||||
|
ace = {};
|
||||||
|
|
||||||
ace.MarkerLayer = function(parentEl)
|
ace.MarkerLayer = function(parentEl) {
|
||||||
{
|
|
||||||
this.element = document.createElement("div");
|
this.element = document.createElement("div");
|
||||||
this.element.className = "layer marker-layer";
|
this.element.className = "layer marker-layer";
|
||||||
parentEl.appendChild(this.element);
|
parentEl.appendChild(this.element);
|
||||||
|
|
@ -10,88 +10,96 @@ ace.MarkerLayer = function(parentEl)
|
||||||
this._markerId = 1;
|
this._markerId = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ace.MarkerLayer.prototype.addMarker = function(range, clazz)
|
ace.MarkerLayer.prototype.addMarker = function(range, clazz) {
|
||||||
{
|
|
||||||
var id = this._markerId++;
|
var id = this._markerId++;
|
||||||
this.markers[id] = {
|
this.markers[id] = {
|
||||||
range: range,
|
range : range,
|
||||||
type: "line",
|
type : "line",
|
||||||
clazz: clazz
|
clazz : clazz
|
||||||
};
|
};
|
||||||
|
|
||||||
this.update();
|
this.update();
|
||||||
return id;
|
return id;
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.MarkerLayer.prototype.removeMarker = function(markerId)
|
ace.MarkerLayer.prototype.removeMarker = function(markerId) {
|
||||||
{
|
|
||||||
var marker = this.markers[markerId];
|
var marker = this.markers[markerId];
|
||||||
if (marker) {
|
if (marker) {
|
||||||
delete(this.markers[markerId]);
|
delete (this.markers[markerId]);
|
||||||
this.update();
|
this.update();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.MarkerLayer.prototype.update = function(config)
|
ace.MarkerLayer.prototype.update = function(config) {
|
||||||
{
|
|
||||||
var config = config || this.config;
|
var config = config || this.config;
|
||||||
if (!config) return;
|
if (!config)
|
||||||
|
return;
|
||||||
|
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
|
||||||
var html = [];
|
var html = [];
|
||||||
for (var key in this.markers)
|
for ( var key in this.markers) {
|
||||||
{
|
|
||||||
var marker = this.markers[key];
|
var marker = this.markers[key];
|
||||||
var range = marker.range;
|
var range = marker.range;
|
||||||
|
|
||||||
if (range.start.row !== range.end.row)
|
if (range.start.row !== range.end.row) {
|
||||||
{
|
if (range.start.row >= config.firstRow
|
||||||
if (range.start.row >= config.firstRow && range.start.row <= config.lastRow)
|
&& range.start.row <= config.lastRow) {
|
||||||
{
|
html
|
||||||
html.push(
|
.push(
|
||||||
"<div class='", marker.clazz, "' style='",
|
"<div class='",
|
||||||
"height:", config.lineHeight, "px;",
|
marker.clazz,
|
||||||
"width:", Math.round(config.width - (range.start.column * config.characterWidth)), "px;",
|
"' style='",
|
||||||
"top:", (range.start.row-config.firstRow) * config.lineHeight, "px;",
|
"height:",
|
||||||
"left:", Math.round(range.start.column * config.characterWidth), "px;'></div>"
|
config.lineHeight,
|
||||||
);
|
"px;",
|
||||||
|
"width:",
|
||||||
|
Math
|
||||||
|
.round(config.width
|
||||||
|
- (range.start.column * config.characterWidth)),
|
||||||
|
"px;", "top:",
|
||||||
|
(range.start.row - config.firstRow)
|
||||||
|
* config.lineHeight, "px;", "left:", Math
|
||||||
|
.round(range.start.column
|
||||||
|
* config.characterWidth),
|
||||||
|
"px;'></div>");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (range.end.row >= config.firstRow && range.end.row <= config.lastRow)
|
if (range.end.row >= config.firstRow
|
||||||
{
|
&& range.end.row <= config.lastRow) {
|
||||||
html.push(
|
html
|
||||||
"<div class='", marker.clazz, "' style='",
|
.push("<div class='", marker.clazz, "' style='",
|
||||||
"height:", config.lineHeight, "px;",
|
"height:", config.lineHeight, "px;", "top:",
|
||||||
"top:", (range.end.row-config.firstRow) * config.lineHeight, "px;",
|
(range.end.row - config.firstRow)
|
||||||
"width:", Math.round(range.end.column * config.characterWidth), "px;'></div>"
|
* config.lineHeight, "px;", "width:",
|
||||||
);
|
Math.round(range.end.column
|
||||||
};
|
* config.characterWidth), "px;'></div>");
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
for (var row=range.start.row+1; row < range.end.row; row++)
|
for ( var row = range.start.row + 1; row < range.end.row; row++) {
|
||||||
{
|
if (row >= config.firstRow && row <= config.lastRow) {
|
||||||
if (row >= config.firstRow && row <= config.lastRow)
|
html.push("<div class='", marker.clazz, "' style='",
|
||||||
{
|
"height:", config.lineHeight, "px;", "width:",
|
||||||
html.push(
|
config.width, "px;", "top:",
|
||||||
"<div class='", marker.clazz, "' style='",
|
(row - config.firstRow) * config.lineHeight,
|
||||||
"height:", config.lineHeight, "px;",
|
"px;'></div>");
|
||||||
"width:", config.width, "px;",
|
|
||||||
"top:", (row-config.firstRow) * config.lineHeight, "px;'></div>"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
}
|
||||||
else
|
;
|
||||||
{
|
}
|
||||||
if (range.start.row >= config.firstRow && range.start.row <= config.lastRow)
|
else {
|
||||||
{
|
if (range.start.row >= config.firstRow
|
||||||
html.push(
|
&& range.start.row <= config.lastRow) {
|
||||||
"<div class='", marker.clazz, "' style='",
|
html.push("<div class='", marker.clazz, "' style='", "height:",
|
||||||
"height:", config.lineHeight, "px;",
|
config.lineHeight, "px;", "width:",
|
||||||
"width:", Math.round((range.end.column - range.start.column) * config.characterWidth), "px;",
|
Math.round((range.end.column - range.start.column)
|
||||||
"top:", (range.start.row-config.firstRow) * config.lineHeight, "px;",
|
* config.characterWidth), "px;", "top:",
|
||||||
"left:", Math.round(range.start.column * config.characterWidth), "px;'></div>"
|
(range.start.row - config.firstRow)
|
||||||
);
|
* config.lineHeight, "px;", "left:", Math
|
||||||
|
.round(range.start.column
|
||||||
|
* config.characterWidth),
|
||||||
|
"px;'></div>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
if (!window.ace) ace = {};
|
if (!window.ace)
|
||||||
|
ace = {};
|
||||||
|
|
||||||
ace.TextDocument = function(text)
|
ace.TextDocument = function(text) {
|
||||||
{
|
|
||||||
this.lines = this._split(text);
|
this.lines = this._split(text);
|
||||||
this.modified = true;
|
this.modified = true;
|
||||||
|
|
||||||
|
|
@ -16,22 +16,20 @@ ace.TextDocument.prototype.addChangeListener = function(listener) {
|
||||||
this.listeners.push(listener);
|
this.listeners.push(listener);
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.TextDocument.prototype.fireChangeEvent = function(firstRow, lastRow)
|
ace.TextDocument.prototype.fireChangeEvent = function(firstRow, lastRow) {
|
||||||
{
|
for ( var i = 0; i < this.listeners.length; i++) {
|
||||||
for (var i=0; i < this.listeners.length; i++) {
|
|
||||||
this.listeners[i](firstRow, lastRow);
|
this.listeners[i](firstRow, lastRow);
|
||||||
};
|
}
|
||||||
|
;
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.TextDocument.prototype.getWidth = function()
|
ace.TextDocument.prototype.getWidth = function() {
|
||||||
{
|
if (this.modified) {
|
||||||
if (this.modified)
|
|
||||||
{
|
|
||||||
this.modified = false;
|
this.modified = false;
|
||||||
|
|
||||||
var lines = this.lines;
|
var lines = this.lines;
|
||||||
var longestLine = 0;
|
var longestLine = 0;
|
||||||
for (var i=0; i < lines.length; i++) {
|
for ( var i = 0; i < lines.length; i++) {
|
||||||
longestLine = Math.max(longestLine, lines[i].length);
|
longestLine = Math.max(longestLine, lines[i].length);
|
||||||
}
|
}
|
||||||
this.width = longestLine;
|
this.width = longestLine;
|
||||||
|
|
@ -69,8 +67,7 @@ ace.TextDocument.prototype.keywords = {
|
||||||
"with" : 1
|
"with" : 1
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.TextDocument.prototype.getLineTokens = function(row)
|
ace.TextDocument.prototype.getLineTokens = function(row) {
|
||||||
{
|
|
||||||
var tokens = [];
|
var tokens = [];
|
||||||
|
|
||||||
var re = /(?:(\s+)|("[^"]*")|('[^']*')|([\[\]\(\)\{\}])|([a-zA-Z_][a-zA-Z0-9_]*)|(\/\/.*)|(.))/g
|
var re = /(?:(\s+)|("[^"]*")|('[^']*')|([\[\]\(\)\{\}])|([a-zA-Z_][a-zA-Z0-9_]*)|(\/\/.*)|(.))/g
|
||||||
|
|
@ -78,23 +75,25 @@ ace.TextDocument.prototype.getLineTokens = function(row)
|
||||||
|
|
||||||
var match;
|
var match;
|
||||||
var line = this.getLine(row);
|
var line = this.getLine(row);
|
||||||
while (match = re.exec(line))
|
while (match = re.exec(line)) {
|
||||||
{
|
|
||||||
var token = {
|
var token = {
|
||||||
type: "text",
|
type : "text",
|
||||||
value: match[0]
|
value : match[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
if (match[2] || match[3]) {
|
if (match[2] || match[3]) {
|
||||||
token.type = "string";
|
token.type = "string";
|
||||||
} else if (match[5] && this.keywords[match[5]]) {
|
}
|
||||||
|
else if (match[5] && this.keywords[match[5]]) {
|
||||||
token.type = "keyword";
|
token.type = "keyword";
|
||||||
} else if (match[6]) {
|
}
|
||||||
|
else if (match[6]) {
|
||||||
token.type = "comment";
|
token.type = "comment";
|
||||||
}
|
}
|
||||||
|
|
||||||
tokens.push(token);
|
tokens.push(token);
|
||||||
};
|
}
|
||||||
|
;
|
||||||
|
|
||||||
return tokens;
|
return tokens;
|
||||||
};
|
};
|
||||||
|
|
@ -103,119 +102,111 @@ ace.TextDocument.prototype.getLength = function() {
|
||||||
return this.lines.length;
|
return this.lines.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.TextDocument.prototype.getTextRange = function(range)
|
ace.TextDocument.prototype.getTextRange = function(range) {
|
||||||
{
|
|
||||||
if (range.start.row == range.end.row) {
|
if (range.start.row == range.end.row) {
|
||||||
return this.lines[range.start.row].substring(range.start.column, range.end.column);
|
return this.lines[range.start.row].substring(range.start.column,
|
||||||
} else {
|
range.end.column);
|
||||||
|
}
|
||||||
|
else {
|
||||||
var lines = [];
|
var lines = [];
|
||||||
lines.push(this.lines[range.start.row].substring(range.start.column));
|
lines.push(this.lines[range.start.row].substring(range.start.column));
|
||||||
lines.push.apply(lines, this.lines.slice(range.start.row+1, range.end.row));
|
lines.push.apply(lines, this.lines.slice(range.start.row + 1,
|
||||||
|
range.end.row));
|
||||||
lines.push(this.lines[range.end.row].substring(0, range.end.column));
|
lines.push(this.lines[range.end.row].substring(0, range.end.column));
|
||||||
|
|
||||||
return lines.join("\n");
|
return lines.join("\n");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.TextDocument.prototype.insert = function(position, text)
|
ace.TextDocument.prototype.insert = function(position, text) {
|
||||||
{
|
|
||||||
var end = this._insert(position, text);
|
var end = this._insert(position, text);
|
||||||
this.fireChangeEvent(
|
this.fireChangeEvent(position.row, position.row == end.row ? position.row
|
||||||
position.row,
|
: undefined);
|
||||||
position.row == end.row ? position.row : undefined
|
|
||||||
);
|
|
||||||
return end;
|
return end;
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.TextDocument.prototype._insert = function(position, text)
|
ace.TextDocument.prototype._insert = function(position, text) {
|
||||||
{
|
|
||||||
this.modified = true;
|
this.modified = true;
|
||||||
|
|
||||||
var newLines = this._split(text);
|
var newLines = this._split(text);
|
||||||
|
|
||||||
if (text == "\n")
|
if (text == "\n") {
|
||||||
{
|
|
||||||
var line = this.lines[position.row] || "";
|
var line = this.lines[position.row] || "";
|
||||||
this.lines[position.row] = line.substring(0, position.column);
|
this.lines[position.row] = line.substring(0, position.column);
|
||||||
this.lines.splice(position.row+1, 0, line.substring(position.column));
|
this.lines.splice(position.row + 1, 0, line.substring(position.column));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
row: position.row + 1,
|
row : position.row + 1,
|
||||||
column: 0
|
column : 0
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else if (newLines.length == 1)
|
else if (newLines.length == 1) {
|
||||||
{
|
|
||||||
var line = this.lines[position.row] || "";
|
var line = this.lines[position.row] || "";
|
||||||
this.lines[position.row] = line.substring(0, position.column) + text + line.substring(position.column);
|
this.lines[position.row] = line.substring(0, position.column) + text
|
||||||
|
+ line.substring(position.column);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
row: position.row,
|
row : position.row,
|
||||||
column: position.column+text.length
|
column : position.column + text.length
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
var line = this.lines[position.row] || "";
|
var line = this.lines[position.row] || "";
|
||||||
|
|
||||||
this.lines[position.row] = line.substring(0, position.column) + newLines[0];
|
this.lines[position.row] = line.substring(0, position.column)
|
||||||
this.lines[position.row+1] = newLines[newLines.length-1] + line.substring(position.column);
|
+ newLines[0];
|
||||||
|
this.lines[position.row + 1] = newLines[newLines.length - 1]
|
||||||
|
+ line.substring(position.column);
|
||||||
|
|
||||||
if (newLines.length > 2)
|
if (newLines.length > 2) {
|
||||||
{
|
var args = [ position.row + 1, 0 ]
|
||||||
var args = [position.row + 1, 0]
|
|
||||||
args.push.apply(args, newLines.slice(1, -1));
|
args.push.apply(args, newLines.slice(1, -1));
|
||||||
this.lines.splice.apply(this.lines, args);
|
this.lines.splice.apply(this.lines, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
row: position.row + newLines.length - 1,
|
row : position.row + newLines.length - 1,
|
||||||
column: newLines[newLines.length-1].length
|
column : newLines[newLines.length - 1].length
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.TextDocument.prototype.remove = function(range)
|
ace.TextDocument.prototype.remove = function(range) {
|
||||||
{
|
|
||||||
var end = this._remove(range);
|
var end = this._remove(range);
|
||||||
|
|
||||||
this.fireChangeEvent(
|
this.fireChangeEvent(range.start.row,
|
||||||
range.start.row,
|
range.end.row == range.start.row ? range.start.row
|
||||||
range.end.row == range.start.row ? range.start.row : undefined
|
: undefined);
|
||||||
);
|
|
||||||
return end;
|
return end;
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.TextDocument.prototype._remove = function(range)
|
ace.TextDocument.prototype._remove = function(range) {
|
||||||
{
|
|
||||||
this.modified = true;
|
this.modified = true;
|
||||||
|
|
||||||
var firstRow = range.start.row;
|
var firstRow = range.start.row;
|
||||||
var lastRow = range.end.row;
|
var lastRow = range.end.row;
|
||||||
|
|
||||||
var row =
|
var row = this.lines[firstRow].substring(0, range.start.column)
|
||||||
this.lines[firstRow].substring(0, range.start.column) +
|
+ this.lines[lastRow].substring(range.end.column);
|
||||||
this.lines[lastRow].substring(range.end.column);
|
|
||||||
|
|
||||||
this.lines.splice(firstRow, lastRow-firstRow+1, row);
|
this.lines.splice(firstRow, lastRow - firstRow + 1, row);
|
||||||
|
|
||||||
return range.start;
|
return range.start;
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.TextDocument.prototype.replace = function(range, text)
|
ace.TextDocument.prototype.replace = function(range, text) {
|
||||||
{
|
|
||||||
this._remove(range);
|
this._remove(range);
|
||||||
if (text) {
|
if (text) {
|
||||||
var end = this._insert(range.start, text);
|
var end = this._insert(range.start, text);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
end = range.start;
|
end = range.start;
|
||||||
}
|
}
|
||||||
|
|
||||||
var lastRemoved = range.end.column == 0 ? range.end.column-1 : range.end.column;
|
var lastRemoved = range.end.column == 0 ? range.end.column - 1
|
||||||
this.fireChangeEvent(
|
: range.end.column;
|
||||||
range.start.row,
|
this.fireChangeEvent(range.start.row, lastRemoved == end.row ? lastRemoved
|
||||||
lastRemoved == end.row ? lastRemoved : undefined
|
: undefined);
|
||||||
);
|
|
||||||
|
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
if (!window.ace) ace = {};
|
if (!window.ace)
|
||||||
|
ace = {};
|
||||||
|
|
||||||
ace.TextInput = function(parentNode, host) {
|
ace.TextInput = function(parentNode, host) {
|
||||||
|
|
||||||
|
|
@ -14,17 +15,18 @@ ace.TextInput = function(parentNode, host) {
|
||||||
var onTextInput = function(e) {
|
var onTextInput = function(e) {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
if (!inCompostion) {
|
if (!inCompostion) {
|
||||||
if (text.value) host.onTextInput(text.value);
|
if (text.value)
|
||||||
|
host.onTextInput(text.value);
|
||||||
text.value = "";
|
text.value = "";
|
||||||
}
|
}
|
||||||
}, 0)
|
}, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
var onCompositionStart = function(e)
|
var onCompositionStart = function(e) {
|
||||||
{
|
|
||||||
inCompostion = true;
|
inCompostion = true;
|
||||||
|
|
||||||
if (text.value) host.onTextInput(text.value);
|
if (text.value)
|
||||||
|
host.onTextInput(text.value);
|
||||||
text.value = "";
|
text.value = "";
|
||||||
|
|
||||||
host.onCompositionStart();
|
host.onCompositionStart();
|
||||||
|
|
@ -35,8 +37,7 @@ ace.TextInput = function(parentNode, host) {
|
||||||
host.onCompositionUpdate(text.value);
|
host.onCompositionUpdate(text.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
var onCompositionEnd = function()
|
var onCompositionEnd = function() {
|
||||||
{
|
|
||||||
inCompostion = false;
|
inCompostion = false;
|
||||||
host.onCompositionEnd();
|
host.onCompositionEnd();
|
||||||
onTextInput();
|
onTextInput();
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
if (!window.ace) ace = {};
|
if (!window.ace)
|
||||||
|
ace = {};
|
||||||
|
|
||||||
ace.TextLayer = function(parentEl)
|
ace.TextLayer = function(parentEl) {
|
||||||
{
|
|
||||||
this.element = document.createElement("div");
|
this.element = document.createElement("div");
|
||||||
this.element.className = "layer text-layer";
|
this.element.className = "layer text-layer";
|
||||||
parentEl.appendChild(this.element);
|
parentEl.appendChild(this.element);
|
||||||
|
|
@ -21,8 +21,7 @@ ace.TextLayer.prototype.getCharacterWidth = function() {
|
||||||
return this.characterWidth;
|
return this.characterWidth;
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.TextLayer.prototype._measureSizes = function()
|
ace.TextLayer.prototype._measureSizes = function() {
|
||||||
{
|
|
||||||
var measureNode = document.createElement("div");
|
var measureNode = document.createElement("div");
|
||||||
var style = measureNode.style;
|
var style = measureNode.style;
|
||||||
style.width = style.height = "auto";
|
style.width = style.height = "auto";
|
||||||
|
|
@ -43,57 +42,49 @@ ace.TextLayer.prototype._measureSizes = function()
|
||||||
this.element.removeChild(measureNode);
|
this.element.removeChild(measureNode);
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.TextLayer.prototype.updateLines = function(layerConfig, firstRow, lastRow)
|
ace.TextLayer.prototype.updateLines = function(layerConfig, firstRow, lastRow) {
|
||||||
{
|
|
||||||
var first = Math.max(firstRow, layerConfig.firstRow);
|
var first = Math.max(firstRow, layerConfig.firstRow);
|
||||||
var last = Math.min(lastRow, layerConfig.lastRow);
|
var last = Math.min(lastRow, layerConfig.lastRow);
|
||||||
|
|
||||||
var lineElements = this.element.childNodes;
|
var lineElements = this.element.childNodes;
|
||||||
|
|
||||||
for (var i=first; i <= last; i++)
|
for ( var i = first; i <= last; i++) {
|
||||||
{
|
|
||||||
var html = [];
|
var html = [];
|
||||||
this.renderLine(html, i);
|
this.renderLine(html, i);
|
||||||
|
|
||||||
var lineElement = lineElements[i-layerConfig.firstRow];
|
var lineElement = lineElements[i - layerConfig.firstRow];
|
||||||
lineElement.innerHTML = html.join("");
|
lineElement.innerHTML = html.join("");
|
||||||
};
|
}
|
||||||
|
;
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.TextLayer.prototype.update = function(config)
|
ace.TextLayer.prototype.update = 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='line ", i % 2 == 0 ? "even" : "odd",
|
||||||
html.push(
|
"' style='height:" + this.lineHeight + "px;", "width:",
|
||||||
"<div class='line ",
|
config.width, "px'>");
|
||||||
i % 2 == 0 ? "even" : "odd",
|
this.renderLine(html, i), html.push("</div>");
|
||||||
"' style='height:" + this.lineHeight + "px;",
|
|
||||||
"width:", config.width, "px'>"
|
|
||||||
);
|
|
||||||
this.renderLine(html, i),
|
|
||||||
html.push("</div>");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.element.innerHTML = html.join("");
|
this.element.innerHTML = html.join("");
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.TextLayer.prototype.renderLine = function(stringBuilder, row)
|
ace.TextLayer.prototype.renderLine = function(stringBuilder, row) {
|
||||||
{
|
|
||||||
var tokens = this.tokenizer.getTokens(row);
|
var tokens = this.tokenizer.getTokens(row);
|
||||||
for (var i=0; i < tokens.length; i++)
|
for ( var i = 0; i < tokens.length; i++) {
|
||||||
{
|
|
||||||
var token = tokens[i];
|
var token = tokens[i];
|
||||||
|
|
||||||
var output = token.value.
|
var output = token.value.replace(/&/g, "&").replace(/</g, "<")
|
||||||
replace(/&/g, "&").
|
.replace(/\s/g, " ");
|
||||||
replace(/</g, "<").
|
|
||||||
replace(/\s/g, " ");
|
|
||||||
|
|
||||||
if (token.type !== "text") {
|
if (token.type !== "text") {
|
||||||
stringBuilder.push("<span class='", token.type, "'>", output, "</span>");
|
stringBuilder.push("<span class='", token.type, "'>", output,
|
||||||
} else {
|
"</span>");
|
||||||
|
}
|
||||||
|
else {
|
||||||
stringBuilder.push(output);
|
stringBuilder.push(output);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
;
|
||||||
};
|
};
|
||||||
|
|
@ -1,25 +1,25 @@
|
||||||
if (!window.ace) ace = {};
|
if (!window.ace)
|
||||||
|
ace = {};
|
||||||
|
|
||||||
ace.Tokenizer = function(rules)
|
ace.Tokenizer = function(rules) {
|
||||||
{
|
|
||||||
this.rules = rules;
|
this.rules = rules;
|
||||||
|
|
||||||
this.regExps = {};
|
this.regExps = {};
|
||||||
for (var key in this.rules)
|
for ( var key in this.rules) {
|
||||||
{
|
|
||||||
var state = this.rules[key];
|
var state = this.rules[key];
|
||||||
var ruleRegExps = [];
|
var ruleRegExps = [];
|
||||||
|
|
||||||
for (var i=0; i < state.length; i++) {
|
for ( var i = 0; i < state.length; i++) {
|
||||||
ruleRegExps.push(state[i].regex);
|
ruleRegExps.push(state[i].regex);
|
||||||
};
|
}
|
||||||
|
;
|
||||||
|
|
||||||
this.regExps[key] = new RegExp("(?:(" + ruleRegExps.join(")|(") + ")|(.))", "g");
|
this.regExps[key] = new RegExp("(?:(" + ruleRegExps.join(")|(")
|
||||||
|
+ ")|(.))", "g");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.Tokenizer.prototype.getLineTokens = function(line, startState)
|
ace.Tokenizer.prototype.getLineTokens = function(line, startState) {
|
||||||
{
|
|
||||||
var currentState = startState;
|
var currentState = startState;
|
||||||
var state = this.rules[currentState];
|
var state = this.rules[currentState];
|
||||||
var re = this.regExps[currentState];
|
var re = this.regExps[currentState];
|
||||||
|
|
@ -29,32 +29,27 @@ ace.Tokenizer.prototype.getLineTokens = function(line, startState)
|
||||||
|
|
||||||
var lastIndex = 0;
|
var lastIndex = 0;
|
||||||
|
|
||||||
while (match = re.exec(line))
|
while (match = re.exec(line)) {
|
||||||
{
|
|
||||||
var token = {
|
var token = {
|
||||||
type: "text",
|
type : "text",
|
||||||
value: match[0]
|
value : match[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
if (re.lastIndex == lastIndex) {
|
if (re.lastIndex == lastIndex) { throw new Error("tokenizer error") }
|
||||||
throw new Error("tokenizer error")
|
|
||||||
}
|
|
||||||
lastIndex = re.lastIndex;
|
lastIndex = re.lastIndex;
|
||||||
|
|
||||||
//console.log(match);
|
// console.log(match);
|
||||||
|
|
||||||
for (var i=0; i < state.length; i++)
|
for ( var i = 0; i < state.length; i++) {
|
||||||
{
|
if (match[i + 1]) {
|
||||||
if (match[i+1])
|
|
||||||
{
|
|
||||||
if (typeof state[i].token == "function") {
|
if (typeof state[i].token == "function") {
|
||||||
token.type = state[i].token(match[0]);
|
token.type = state[i].token(match[0]);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
token.type = state[i].token;
|
token.type = state[i].token;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state[i].next && state[i].next !== currentState)
|
if (state[i].next && state[i].next !== currentState) {
|
||||||
{
|
|
||||||
currentState = state[i].next;
|
currentState = state[i].next;
|
||||||
var state = this.rules[currentState];
|
var state = this.rules[currentState];
|
||||||
var lastIndex = re.lastIndex;
|
var lastIndex = re.lastIndex;
|
||||||
|
|
@ -64,15 +59,17 @@ ace.Tokenizer.prototype.getLineTokens = function(line, startState)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
;
|
||||||
|
|
||||||
tokens.push(token);
|
tokens.push(token);
|
||||||
};
|
}
|
||||||
|
;
|
||||||
|
|
||||||
//console.log(tokens, currentState)
|
// console.log(tokens, currentState)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
tokens: tokens,
|
tokens : tokens,
|
||||||
state: currentState
|
state : currentState
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
if (!window.ace) ace = {};
|
if (!window.ace)
|
||||||
|
ace = {};
|
||||||
|
|
||||||
ace.VirtualRenderer = function(container)
|
ace.VirtualRenderer = function(container) {
|
||||||
{
|
|
||||||
this.container = container;
|
this.container = container;
|
||||||
this.container.className += "editor";
|
this.container.className += "editor";
|
||||||
|
|
||||||
|
|
@ -24,18 +24,17 @@ ace.VirtualRenderer = function(container)
|
||||||
|
|
||||||
this.cursorLayer = new ace.CursorLayer(this.scroller);
|
this.cursorLayer = new ace.CursorLayer(this.scroller);
|
||||||
|
|
||||||
this.layers = [this.markerLayer, textLayer, this.cursorLayer];
|
this.layers = [ this.markerLayer, textLayer, this.cursorLayer ];
|
||||||
|
|
||||||
this.scrollTop = 0;
|
this.scrollTop = 0;
|
||||||
|
|
||||||
this.cursorPos = {
|
this.cursorPos = {
|
||||||
row: 0,
|
row : 0,
|
||||||
column: 0
|
column : 0
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
ace.VirtualRenderer.prototype.setDocument = function(doc)
|
ace.VirtualRenderer.prototype.setDocument = function(doc) {
|
||||||
{
|
|
||||||
this.lines = doc.lines;
|
this.lines = doc.lines;
|
||||||
this.doc = doc;
|
this.doc = doc;
|
||||||
};
|
};
|
||||||
|
|
@ -56,18 +55,14 @@ ace.VirtualRenderer.prototype.getLastVisibleRow = function() {
|
||||||
return this.layerConfig.lastRow || 0;
|
return this.layerConfig.lastRow || 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.VirtualRenderer.prototype.updateLines = function(firstRow, lastRow)
|
ace.VirtualRenderer.prototype.updateLines = function(firstRow, lastRow) {
|
||||||
{
|
|
||||||
var layerConfig = this.layerConfig;
|
var layerConfig = this.layerConfig;
|
||||||
|
|
||||||
// if the first row is below the viewport -> ignore it
|
// if the first row is below the viewport -> ignore it
|
||||||
if (firstRow > layerConfig.lastRow+1) {
|
if (firstRow > layerConfig.lastRow + 1) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the last row is unknow -> redraw everything
|
// if the last row is unknow -> redraw everything
|
||||||
if (lastRow === undefined)
|
if (lastRow === undefined) {
|
||||||
{
|
|
||||||
this.draw()
|
this.draw()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -76,32 +71,29 @@ ace.VirtualRenderer.prototype.updateLines = function(firstRow, lastRow)
|
||||||
this.textLayer.updateLines(layerConfig, firstRow, lastRow);
|
this.textLayer.updateLines(layerConfig, firstRow, lastRow);
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.VirtualRenderer.prototype.draw = function()
|
ace.VirtualRenderer.prototype.draw = function() {
|
||||||
{
|
|
||||||
var lines = this.lines;
|
var lines = this.lines;
|
||||||
|
|
||||||
var offset = this.scrollTop % this.lineHeight;
|
var offset = this.scrollTop % this.lineHeight;
|
||||||
var minHeight = this.scroller.clientHeight + offset;
|
var minHeight = this.scroller.clientHeight + offset;
|
||||||
|
|
||||||
var longestLine = Math.max(
|
var longestLine = Math.max(this.scroller.clientWidth, Math.round(this.doc
|
||||||
this.scroller.clientWidth,
|
.getWidth()
|
||||||
Math.round(this.doc.getWidth() * this.characterWidth)
|
* this.characterWidth));
|
||||||
);
|
|
||||||
|
|
||||||
var lineCount = Math.ceil(minHeight / this.lineHeight);
|
var lineCount = Math.ceil(minHeight / this.lineHeight);
|
||||||
var firstRow = Math.round((this.scrollTop - offset) / this.lineHeight);
|
var firstRow = Math.round((this.scrollTop - offset) / this.lineHeight);
|
||||||
var lastRow = Math.min(lines.length, firstRow+lineCount)-1;
|
var lastRow = Math.min(lines.length, firstRow + lineCount) - 1;
|
||||||
|
|
||||||
var layerConfig = this.layerConfig = {
|
var layerConfig = this.layerConfig = {
|
||||||
width: longestLine,
|
width : longestLine,
|
||||||
firstRow: firstRow,
|
firstRow : firstRow,
|
||||||
lastRow: lastRow,
|
lastRow : lastRow,
|
||||||
lineHeight: this.lineHeight,
|
lineHeight : this.lineHeight,
|
||||||
characterWidth: this.characterWidth
|
characterWidth : this.characterWidth
|
||||||
};
|
};
|
||||||
|
|
||||||
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];
|
||||||
|
|
||||||
var style = layer.element.style;
|
var style = layer.element.style;
|
||||||
|
|
@ -110,7 +102,8 @@ ace.VirtualRenderer.prototype.draw = function()
|
||||||
style.width = longestLine + "px";
|
style.width = longestLine + "px";
|
||||||
|
|
||||||
layer.update(layerConfig);
|
layer.update(layerConfig);
|
||||||
};
|
}
|
||||||
|
;
|
||||||
|
|
||||||
this.gutterLayer.element.style.marginTop = (-offset) + "px";
|
this.gutterLayer.element.style.marginTop = (-offset) + "px";
|
||||||
this.gutterLayer.element.style.height = minHeight + "px";
|
this.gutterLayer.element.style.height = minHeight + "px";
|
||||||
|
|
@ -125,8 +118,7 @@ ace.VirtualRenderer.prototype.removeMarker = function(markerId) {
|
||||||
this.markerLayer.removeMarker(markerId);
|
this.markerLayer.removeMarker(markerId);
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.VirtualRenderer.prototype.updateCursor = function(position)
|
ace.VirtualRenderer.prototype.updateCursor = function(position) {
|
||||||
{
|
|
||||||
this.cursorLayer.setCursor(position);
|
this.cursorLayer.setCursor(position);
|
||||||
this.cursorLayer.update(this.layerConfig);
|
this.cursorLayer.update(this.layerConfig);
|
||||||
};
|
};
|
||||||
|
|
@ -139,8 +131,7 @@ ace.VirtualRenderer.prototype.showCursor = function() {
|
||||||
this.cursorLayer.showCursor();
|
this.cursorLayer.showCursor();
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.VirtualRenderer.prototype.scrollCursorIntoView = function()
|
ace.VirtualRenderer.prototype.scrollCursorIntoView = function() {
|
||||||
{
|
|
||||||
var pos = this.cursorLayer.getPixelPosition();
|
var pos = this.cursorLayer.getPixelPosition();
|
||||||
|
|
||||||
var left = pos.left
|
var left = pos.left
|
||||||
|
|
@ -150,7 +141,8 @@ ace.VirtualRenderer.prototype.scrollCursorIntoView = function()
|
||||||
this.scrollToY(top);
|
this.scrollToY(top);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.getScrollTop() + this.scroller.clientHeight < top + this.lineHeight) {
|
if (this.getScrollTop() + this.scroller.clientHeight < top
|
||||||
|
+ this.lineHeight) {
|
||||||
this.scrollToY(top + this.lineHeight - this.scroller.clientHeight);
|
this.scrollToY(top + this.lineHeight - this.scroller.clientHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -158,8 +150,10 @@ ace.VirtualRenderer.prototype.scrollCursorIntoView = function()
|
||||||
this.scroller.scrollLeft = left;
|
this.scroller.scrollLeft = left;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.scroller.scrollLeft + this.scroller.clientWidth < left + this.characterWidth) {
|
if (this.scroller.scrollLeft + this.scroller.clientWidth < left
|
||||||
this.scroller.scrollLeft = Math.round(left + this.characterWidth - this.scroller.clientWidth);
|
+ this.characterWidth) {
|
||||||
|
this.scroller.scrollLeft = Math.round(left + this.characterWidth
|
||||||
|
- this.scroller.clientWidth);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -168,12 +162,12 @@ ace.VirtualRenderer.prototype.getScrollTop = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.VirtualRenderer.prototype.scrollToRow = function(row) {
|
ace.VirtualRenderer.prototype.scrollToRow = function(row) {
|
||||||
this.scrollToY(row*this.lineHeight);
|
this.scrollToY(row * this.lineHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
ace.VirtualRenderer.prototype.scrollToY = function(scrollTop)
|
ace.VirtualRenderer.prototype.scrollToY = function(scrollTop) {
|
||||||
{
|
var maxHeight = this.lines.length * this.lineHeight
|
||||||
var maxHeight = this.lines.length * this.lineHeight - this.scroller.clientHeight;
|
- this.scroller.clientHeight;
|
||||||
var scrollTop = Math.max(0, Math.min(maxHeight, scrollTop));
|
var scrollTop = Math.max(0, Math.min(maxHeight, scrollTop));
|
||||||
|
|
||||||
if (this.scrollTop !== scrollTop) {
|
if (this.scrollTop !== scrollTop) {
|
||||||
|
|
@ -182,16 +176,17 @@ ace.VirtualRenderer.prototype.scrollToY = function(scrollTop)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.VirtualRenderer.prototype.screenToTextCoordinates = function(pageX, pageY)
|
ace.VirtualRenderer.prototype.screenToTextCoordinates = function(pageX, pageY) {
|
||||||
{
|
|
||||||
var canvasPos = this.scroller.getBoundingClientRect();
|
var canvasPos = this.scroller.getBoundingClientRect();
|
||||||
|
|
||||||
var col = Math.floor((pageX + this.scroller.scrollLeft - canvasPos.left) / this.characterWidth);
|
var col = Math.floor((pageX + this.scroller.scrollLeft - canvasPos.left)
|
||||||
var row = Math.floor((pageY + this.scrollTop - canvasPos.top) / this.lineHeight);
|
/ this.characterWidth);
|
||||||
|
var row = Math.floor((pageY + this.scrollTop - canvasPos.top)
|
||||||
|
/ this.lineHeight);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
row: row,
|
row : row,
|
||||||
column: col
|
column : col
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
153
src/XML.js
153
src/XML.js
|
|
@ -1,98 +1,75 @@
|
||||||
if (!window.ace) ace = {};
|
if (!window.ace)
|
||||||
|
ace = {};
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
ace.XML = {};
|
ace.XML = {};
|
||||||
|
|
||||||
// regexp must not have capturing parentheses
|
// regexp must not have capturing parentheses
|
||||||
// regexps are ordered -> the first match is used
|
// regexps are ordered -> the first match is used
|
||||||
|
|
||||||
ace.XML.RULES = {
|
ace.XML.RULES = {
|
||||||
start :
|
start : [ {
|
||||||
[
|
token : "text",
|
||||||
{
|
regex : "<\\!\\[CDATA\\[",
|
||||||
token: "text",
|
next : "cdata"
|
||||||
regex: "<\\!\\[CDATA\\[",
|
}, {
|
||||||
next: "cdata"
|
token : "xml_pe",
|
||||||
},
|
regex : "<\\?.*?\\?>"
|
||||||
{
|
}, {
|
||||||
token: "xml_pe",
|
token : "comment",
|
||||||
regex: "<\\?.*?\\?>"
|
regex : "<\\!--",
|
||||||
},
|
next : "comment"
|
||||||
{
|
}, {
|
||||||
token: "comment",
|
token : "text", // opening tag
|
||||||
regex: "<\\!--",
|
regex : "<",
|
||||||
next: "comment"
|
next : "tag"
|
||||||
},
|
}, {
|
||||||
{
|
token : "text",
|
||||||
token: "text", // opening tag
|
regex : "\\s+"
|
||||||
regex: "<",
|
}, {
|
||||||
next: "tag"
|
token : "text",
|
||||||
},
|
regex : ".+"
|
||||||
{
|
} ],
|
||||||
token: "text",
|
|
||||||
regex: "\\s+"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
token: "text",
|
|
||||||
regex: ".+"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
tag:
|
tag : [ {
|
||||||
[
|
token : "text",
|
||||||
{
|
regex : ">",
|
||||||
token: "text",
|
next : "start"
|
||||||
regex: ">",
|
}, {
|
||||||
next: "start"
|
token : "keyword",
|
||||||
},
|
regex : "[-_a-zA-Z0-9:]+"
|
||||||
{
|
}, {
|
||||||
token: "keyword",
|
token : "text",
|
||||||
regex: "[-_a-zA-Z0-9:]+"
|
regex : "\\s+"
|
||||||
},
|
}, {
|
||||||
{
|
token : "string",
|
||||||
token: "text",
|
regex : '".*?"'
|
||||||
regex: "\\s+"
|
}, {
|
||||||
},
|
token : "string",
|
||||||
{
|
regex : "'.*?'"
|
||||||
token: "string",
|
} ],
|
||||||
regex: '".*?"'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
token: "string",
|
|
||||||
regex: "'.*?'"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
cdata:
|
cdata : [ {
|
||||||
[
|
token : "text",
|
||||||
{
|
regex : "\\]\\]>",
|
||||||
token: "text",
|
next : "start"
|
||||||
regex: "\\]\\]>",
|
}, {
|
||||||
next: "start"
|
token : "text",
|
||||||
},
|
regex : "\\s+"
|
||||||
{
|
}, {
|
||||||
token: "text",
|
token : "text",
|
||||||
regex: "\\s+"
|
regex : ".+"
|
||||||
},
|
} ],
|
||||||
{
|
|
||||||
token: "text",
|
|
||||||
regex: ".+"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
comment:
|
comment : [ {
|
||||||
[
|
token : "comment",
|
||||||
{
|
regex : ".*?-->",
|
||||||
token: "comment",
|
next : "start"
|
||||||
regex: ".*?-->",
|
}, {
|
||||||
next: "start"
|
token : "comment",
|
||||||
},
|
regex : ".+"
|
||||||
{
|
} ]
|
||||||
token: "comment",
|
};
|
||||||
regex: ".+"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
})();
|
})();
|
||||||
70
src/lib.js
70
src/lib.js
|
|
@ -1,11 +1,12 @@
|
||||||
if (!window.ace) ace = {};
|
if (!window.ace)
|
||||||
|
ace = {};
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
ace.addListener = function(elem, type, callback) {
|
ace.addListener = function(elem, type, callback) {
|
||||||
if (elem.addEventListener) {
|
if (elem.addEventListener) { return elem.addEventListener(type,
|
||||||
return elem.addEventListener(type, callback, false);
|
callback,
|
||||||
}
|
false); }
|
||||||
if (elem.attachEvent) {
|
if (elem.attachEvent) {
|
||||||
var wrapper = function() {
|
var wrapper = function() {
|
||||||
callback(window.event);
|
callback(window.event);
|
||||||
|
|
@ -16,9 +17,8 @@ ace.addListener = function(elem, type, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ace.removeListener = function(elem, type, callback) {
|
ace.removeListener = function(elem, type, callback) {
|
||||||
if (elem.removeEventListener) {
|
if (elem.removeEventListener) { return elem
|
||||||
return elem.removeEventListener(type, callback, false);
|
.removeEventListener(type, callback, false); }
|
||||||
}
|
|
||||||
if (elem.detachEvent) {
|
if (elem.detachEvent) {
|
||||||
elem.detachEvent("on" + type, callback.$$wrapper || callback);
|
elem.detachEvent("on" + type, callback.$$wrapper || callback);
|
||||||
}
|
}
|
||||||
|
|
@ -46,8 +46,7 @@ ace.stopPropagation = function(e) {
|
||||||
e.cancelBubble = true;
|
e.cancelBubble = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ace.preventDefault = function(e)
|
ace.preventDefault = function(e) {
|
||||||
{
|
|
||||||
if (e.preventDefault)
|
if (e.preventDefault)
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
else
|
else
|
||||||
|
|
@ -55,36 +54,29 @@ ace.preventDefault = function(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
ace.inherits = function(ctor, superCtor) {
|
ace.inherits = function(ctor, superCtor) {
|
||||||
var tempCtor = function(){};
|
var tempCtor = function() {
|
||||||
|
};
|
||||||
tempCtor.prototype = superCtor.prototype;
|
tempCtor.prototype = superCtor.prototype;
|
||||||
ctor.super_ = superCtor.prototype;
|
ctor.super_ = superCtor.prototype;
|
||||||
ctor.prototype = new tempCtor();
|
ctor.prototype = new tempCtor();
|
||||||
ctor.prototype.constructor = ctor;
|
ctor.prototype.constructor = ctor;
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.getInnerWidth = function(element)
|
ace.getInnerWidth = function(element) {
|
||||||
{
|
return (parseInt(ace.computedStyle(element, "paddingLeft"))
|
||||||
return (
|
+ parseInt(ace.computedStyle(element, "paddingRight")) + element.clientWidth);
|
||||||
parseInt(ace.computedStyle(element, "paddingLeft")) +
|
|
||||||
parseInt(ace.computedStyle(element, "paddingRight")) +
|
|
||||||
element.clientWidth
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.getInnerHeight = function(element)
|
ace.getInnerHeight = function(element) {
|
||||||
{
|
return (parseInt(ace.computedStyle(element, "paddingTop"))
|
||||||
return (
|
+ parseInt(ace.computedStyle(element, "paddingBottom")) + element.clientHeight);
|
||||||
parseInt(ace.computedStyle(element, "paddingTop")) +
|
|
||||||
parseInt(ace.computedStyle(element, "paddingBottom")) +
|
|
||||||
element.clientHeight
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.computedStyle = function(element, style)
|
ace.computedStyle = function(element, style) {
|
||||||
{
|
|
||||||
if (window.getComputedStyle) {
|
if (window.getComputedStyle) {
|
||||||
return (window.getComputedStyle(element, null))[style];
|
return (window.getComputedStyle(element, null))[style];
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return element.currentStyle[style];
|
return element.currentStyle[style];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -111,16 +103,13 @@ ace.bind = function(fcn, context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ace.capture = function(el, eventHandler, releaseCaptureHandler)
|
ace.capture = function(el, eventHandler, releaseCaptureHandler) {
|
||||||
{
|
function onMouseMove(e) {
|
||||||
function onMouseMove(e)
|
|
||||||
{
|
|
||||||
eventHandler(e);
|
eventHandler(e);
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
}
|
}
|
||||||
|
|
||||||
function onMouseUp(e)
|
function onMouseUp(e) {
|
||||||
{
|
|
||||||
eventHandler && eventHandler(e);
|
eventHandler && eventHandler(e);
|
||||||
releaseCaptureHandler && releaseCaptureHandler();
|
releaseCaptureHandler && releaseCaptureHandler();
|
||||||
|
|
||||||
|
|
@ -134,20 +123,18 @@ ace.capture = function(el, eventHandler, releaseCaptureHandler)
|
||||||
document.addEventListener("mouseup", onMouseUp, true);
|
document.addEventListener("mouseup", onMouseUp, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
ace.addMouseWheelListener = function(el, callback)
|
ace.addMouseWheelListener = function(el, callback) {
|
||||||
{
|
|
||||||
var listener = function(e) {
|
var listener = function(e) {
|
||||||
e.wheel = (e.wheelDelta) ? e.wheelDelta / 120 : -(e.detail || 0) / 3;
|
e.wheel = (e.wheelDelta) ? e.wheelDelta / 120
|
||||||
|
: -(e.detail || 0) / 3;
|
||||||
callback(e);
|
callback(e);
|
||||||
}
|
}
|
||||||
ace.addListener(el, "DOMMouseScroll", listener);
|
ace.addListener(el, "DOMMouseScroll", listener);
|
||||||
ace.addListener(el, "mousewheel", listener);
|
ace.addListener(el, "mousewheel", listener);
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.autoremoveListener = function(el, type, callback, timeout)
|
ace.autoremoveListener = function(el, type, callback, timeout) {
|
||||||
{
|
var listener = function(e) {
|
||||||
var listener = function(e)
|
|
||||||
{
|
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
remove();
|
remove();
|
||||||
callback(e);
|
callback(e);
|
||||||
|
|
@ -161,8 +148,7 @@ ace.autoremoveListener = function(el, type, callback, timeout)
|
||||||
var timeoutId = setTimeout(remove, timeout);
|
var timeoutId = setTimeout(remove, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
ace.addTripleClickListener = function(el, callback)
|
ace.addTripleClickListener = function(el, callback) {
|
||||||
{
|
|
||||||
ace.addListener(el, "mousedown", function() {
|
ace.addListener(el, "mousedown", function() {
|
||||||
ace.autoremoveListener(el, "mousedown", function() {
|
ace.autoremoveListener(el, "mousedown", function() {
|
||||||
ace.autoremoveListener(el, "mousedown", callback, 300);
|
ace.autoremoveListener(el, "mousedown", callback, 300);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue