make jslint happy
This commit is contained in:
parent
8fe20516d4
commit
443b712b8f
15 changed files with 968 additions and 949 deletions
|
|
@ -1,3 +1,3 @@
|
||||||
onmessage = function(e) {
|
onmessage = function(e) {
|
||||||
onmessage = new Function("e", e.data);
|
onmessage = new Function("e", e.data);
|
||||||
}
|
};
|
||||||
|
|
@ -45,7 +45,7 @@ ace.BackgroundTokenizer = function(tokenizer, onUpdate, onComplete) {
|
||||||
|
|
||||||
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) {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ ace.CursorLayer = function(parentEl) {
|
||||||
this.cursor.className = "cursor";
|
this.cursor.className = "cursor";
|
||||||
|
|
||||||
this.isVisible = false;
|
this.isVisible = false;
|
||||||
}
|
};
|
||||||
|
|
||||||
ace.CursorLayer.prototype.setCursor = function(position) {
|
ace.CursorLayer.prototype.setCursor = function(position) {
|
||||||
this.position = {
|
this.position = {
|
||||||
|
|
@ -47,7 +47,7 @@ ace.CursorLayer.prototype.getPixelPosition = function() {
|
||||||
left : 0,
|
left : 0,
|
||||||
top : 0
|
top : 0
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
ace.CursorLayer.prototype.update = function(config) {
|
ace.CursorLayer.prototype.update = function(config) {
|
||||||
if (!this.position)
|
if (!this.position)
|
||||||
|
|
|
||||||
1264
src/Editor.js
1264
src/Editor.js
File diff suppressed because it is too large
Load diff
|
|
@ -5,7 +5,7 @@ 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 = [];
|
||||||
|
|
|
||||||
|
|
@ -3,112 +3,112 @@ if (!window.ace)
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
ace.JavaScript = {};
|
ace.JavaScript = {};
|
||||||
|
|
||||||
var keywords = {
|
var keywords = {
|
||||||
"break" : 1,
|
"break" : 1,
|
||||||
"case" : 1,
|
"case" : 1,
|
||||||
"catch" : 1,
|
"catch" : 1,
|
||||||
"continue" : 1,
|
"continue" : 1,
|
||||||
"default" : 1,
|
"default" : 1,
|
||||||
"delete" : 1,
|
"delete" : 1,
|
||||||
"do" : 1,
|
"do" : 1,
|
||||||
"else" : 1,
|
"else" : 1,
|
||||||
"finally" : 1,
|
"finally" : 1,
|
||||||
"for" : 1,
|
"for" : 1,
|
||||||
"function" : 1,
|
"function" : 1,
|
||||||
"if" : 1,
|
"if" : 1,
|
||||||
"in" : 1,
|
"in" : 1,
|
||||||
"instanceof" : 1,
|
"instanceof" : 1,
|
||||||
"new" : 1,
|
"new" : 1,
|
||||||
"return" : 1,
|
"return" : 1,
|
||||||
"switch" : 1,
|
"switch" : 1,
|
||||||
"throw" : 1,
|
"throw" : 1,
|
||||||
"try" : 1,
|
"try" : 1,
|
||||||
"typeof" : 1,
|
"typeof" : 1,
|
||||||
"var" : 1,
|
"var" : 1,
|
||||||
"while" : 1,
|
"while" : 1,
|
||||||
"with" : 1
|
"with" : 1
|
||||||
};
|
};
|
||||||
|
|
||||||
// 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.JavaScript.RULES = {
|
ace.JavaScript.RULES = {
|
||||||
start : [ {
|
start : [ {
|
||||||
token : "comment",
|
token : "comment",
|
||||||
regex : "\\/\\/.*$"
|
regex : "\\/\\/.*$"
|
||||||
}, {
|
}, {
|
||||||
token : "comment", // multi line comment in one line
|
token : "comment", // multi line comment in one line
|
||||||
regex : "\\/\\*.*?\\*\\/"
|
regex : "\\/\\*.*?\\*\\/"
|
||||||
}, {
|
}, {
|
||||||
token : "comment", // multi line comment start
|
token : "comment", // multi line comment start
|
||||||
regex : "\\/\\*.*$",
|
regex : "\\/\\*.*$",
|
||||||
next : "comment"
|
next : "comment"
|
||||||
}, {
|
}, {
|
||||||
token : "string", // single line
|
token : "string", // single line
|
||||||
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
|
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
|
||||||
}, {
|
}, {
|
||||||
token : "string", // multi line string start
|
token : "string", // multi line string start
|
||||||
regex : '["].*\\\\$',
|
regex : '["].*\\\\$',
|
||||||
next : "qqstring"
|
next : "qqstring"
|
||||||
}, {
|
}, {
|
||||||
token : "string", // single line
|
token : "string", // single line
|
||||||
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
|
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
|
||||||
}, {
|
}, {
|
||||||
token : "string", // multi line string start
|
token : "string", // multi line string start
|
||||||
regex : "['].*\\\\$",
|
regex : "['].*\\\\$",
|
||||||
next : "qstring"
|
next : "qstring"
|
||||||
}, {
|
}, {
|
||||||
token : "number", // hex
|
token : "number", // hex
|
||||||
regex : "0[xX][0-9a-fA-F]+\\b"
|
regex : "0[xX][0-9a-fA-F]+\\b"
|
||||||
}, {
|
}, {
|
||||||
token : "number", // float
|
token : "number", // float
|
||||||
regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
|
regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
|
||||||
}, {
|
}, {
|
||||||
token : function(value) {
|
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"
|
||||||
|
}, {
|
||||||
|
token : function(value) {
|
||||||
|
// return parens[value];
|
||||||
|
return "text";
|
||||||
},
|
},
|
||||||
regex : "[a-zA-Z_][a-zA-Z0-9_]*\\b"
|
regex : "[\\[\\]\\(\\)\\{\\}]"
|
||||||
}, {
|
}, {
|
||||||
token : function(value) {
|
token : "text",
|
||||||
// return parens[value];
|
regex : "\\s+"
|
||||||
return "text";
|
} ],
|
||||||
},
|
"comment" : [ {
|
||||||
regex : "[\\[\\]\\(\\)\\{\\}]"
|
token : "comment", // closing comment
|
||||||
}, {
|
regex : ".*?\\*\\/",
|
||||||
token : "text",
|
next : "start"
|
||||||
regex : "\\s+"
|
}, {
|
||||||
} ],
|
token : "comment", // comment spanning whole line
|
||||||
"comment" : [ {
|
regex : ".+"
|
||||||
token : "comment", // closing comment
|
} ],
|
||||||
regex : ".*?\\*\\/",
|
"qqstring" : [ {
|
||||||
next : "start"
|
token : "string",
|
||||||
}, {
|
regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
|
||||||
token : "comment", // comment spanning whole line
|
next : "start"
|
||||||
regex : ".+"
|
}, {
|
||||||
} ],
|
token : "string",
|
||||||
"qqstring" : [ {
|
regex : '.+'
|
||||||
token : "string",
|
} ],
|
||||||
regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
|
"qstring" : [ {
|
||||||
next : "start"
|
token : "string",
|
||||||
}, {
|
regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
|
||||||
token : "string",
|
next : "start"
|
||||||
regex : '.+'
|
}, {
|
||||||
} ],
|
token : "string",
|
||||||
"qstring" : [ {
|
regex : '.+'
|
||||||
token : "string",
|
} ]
|
||||||
regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
|
};
|
||||||
next : "start"
|
|
||||||
}, {
|
|
||||||
token : "string",
|
|
||||||
regex : '.+'
|
|
||||||
} ]
|
|
||||||
};
|
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
@ -8,7 +8,7 @@ ace.MarkerLayer = function(parentEl) {
|
||||||
|
|
||||||
this.markers = {};
|
this.markers = {};
|
||||||
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++;
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,10 @@ ace.TextDocument = function(text) {
|
||||||
this.modified = true;
|
this.modified = true;
|
||||||
|
|
||||||
this.listeners = [];
|
this.listeners = [];
|
||||||
}
|
};
|
||||||
|
|
||||||
ace.TextDocument.prototype._split = function(text) {
|
ace.TextDocument.prototype._split = function(text) {
|
||||||
return text.split(/[\n\r]/)
|
return text.split(/[\n\r]/);
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.TextDocument.prototype.addChangeListener = function(listener) {
|
ace.TextDocument.prototype.addChangeListener = function(listener) {
|
||||||
|
|
@ -67,37 +67,6 @@ ace.TextDocument.prototype.keywords = {
|
||||||
"with" : 1
|
"with" : 1
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.TextDocument.prototype.getLineTokens = function(row) {
|
|
||||||
var tokens = [];
|
|
||||||
|
|
||||||
var re = /(?:(\s+)|("[^"]*")|('[^']*')|([\[\]\(\)\{\}])|([a-zA-Z_][a-zA-Z0-9_]*)|(\/\/.*)|(.))/g
|
|
||||||
re.lastIndex = 0;
|
|
||||||
|
|
||||||
var match;
|
|
||||||
var line = this.getLine(row);
|
|
||||||
while (match = re.exec(line)) {
|
|
||||||
var token = {
|
|
||||||
type : "text",
|
|
||||||
value : match[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
if (match[2] || match[3]) {
|
|
||||||
token.type = "string";
|
|
||||||
}
|
|
||||||
else if (match[5] && this.keywords[match[5]]) {
|
|
||||||
token.type = "keyword";
|
|
||||||
}
|
|
||||||
else if (match[6]) {
|
|
||||||
token.type = "comment";
|
|
||||||
}
|
|
||||||
|
|
||||||
tokens.push(token);
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
return tokens;
|
|
||||||
};
|
|
||||||
|
|
||||||
ace.TextDocument.prototype.getLength = function() {
|
ace.TextDocument.prototype.getLength = function() {
|
||||||
return this.lines.length;
|
return this.lines.length;
|
||||||
};
|
};
|
||||||
|
|
@ -148,7 +117,7 @@ ace.TextDocument.prototype._insert = function(position, text) {
|
||||||
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] || "";
|
||||||
|
|
@ -159,7 +128,7 @@ ace.TextDocument.prototype._insert = function(position, text) {
|
||||||
+ line.substring(position.column);
|
+ 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);
|
||||||
}
|
}
|
||||||
|
|
@ -209,4 +178,4 @@ ace.TextDocument.prototype.replace = function(range, text) {
|
||||||
: undefined);
|
: undefined);
|
||||||
|
|
||||||
return end;
|
return end;
|
||||||
}
|
};
|
||||||
|
|
@ -19,8 +19,8 @@ ace.TextInput = function(parentNode, host) {
|
||||||
host.onTextInput(text.value);
|
host.onTextInput(text.value);
|
||||||
text.value = "";
|
text.value = "";
|
||||||
}
|
}
|
||||||
}, 0)
|
}, 0);
|
||||||
}
|
};
|
||||||
|
|
||||||
var onCompositionStart = function(e) {
|
var onCompositionStart = function(e) {
|
||||||
inCompostion = true;
|
inCompostion = true;
|
||||||
|
|
@ -31,28 +31,28 @@ ace.TextInput = function(parentNode, host) {
|
||||||
|
|
||||||
host.onCompositionStart();
|
host.onCompositionStart();
|
||||||
setTimeout(onCompositionUpdate, 0);
|
setTimeout(onCompositionUpdate, 0);
|
||||||
}
|
};
|
||||||
|
|
||||||
var onCompositionUpdate = function() {
|
var onCompositionUpdate = function() {
|
||||||
host.onCompositionUpdate(text.value);
|
host.onCompositionUpdate(text.value);
|
||||||
}
|
};
|
||||||
|
|
||||||
var onCompositionEnd = function() {
|
var onCompositionEnd = function() {
|
||||||
inCompostion = false;
|
inCompostion = false;
|
||||||
host.onCompositionEnd();
|
host.onCompositionEnd();
|
||||||
onTextInput();
|
onTextInput();
|
||||||
}
|
};
|
||||||
|
|
||||||
var onCopy = function() {
|
var onCopy = function() {
|
||||||
text.value = host.getCopyText();
|
text.value = host.getCopyText();
|
||||||
text.select();
|
text.select();
|
||||||
}
|
};
|
||||||
|
|
||||||
var onCut = function() {
|
var onCut = function() {
|
||||||
text.value = host.getCopyText();
|
text.value = host.getCopyText();
|
||||||
host.onCut();
|
host.onCut();
|
||||||
text.select();
|
text.select();
|
||||||
}
|
};
|
||||||
|
|
||||||
ace.addListener(text, "keypress", onTextInput, false);
|
ace.addListener(text, "keypress", onTextInput, false);
|
||||||
ace.addListener(text, "textInput", onTextInput, false);
|
ace.addListener(text, "textInput", onTextInput, false);
|
||||||
|
|
@ -77,9 +77,9 @@ ace.TextInput = function(parentNode, host) {
|
||||||
|
|
||||||
this.focus = function() {
|
this.focus = function() {
|
||||||
text.focus();
|
text.focus();
|
||||||
}
|
};
|
||||||
|
|
||||||
this.blur = function() {
|
this.blur = function() {
|
||||||
this.blur();
|
this.blur();
|
||||||
}
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -7,7 +7,7 @@ ace.TextLayer = function(parentEl) {
|
||||||
parentEl.appendChild(this.element);
|
parentEl.appendChild(this.element);
|
||||||
|
|
||||||
this._measureSizes();
|
this._measureSizes();
|
||||||
}
|
};
|
||||||
|
|
||||||
ace.TextLayer.prototype.setTokenizer = function(tokenizer) {
|
ace.TextLayer.prototype.setTokenizer = function(tokenizer) {
|
||||||
this.tokenizer = tokenizer;
|
this.tokenizer = tokenizer;
|
||||||
|
|
|
||||||
|
|
@ -33,9 +33,9 @@ ace.Tokenizer.prototype.getLineTokens = function(line, startState) {
|
||||||
var token = {
|
var token = {
|
||||||
type : "text",
|
type : "text",
|
||||||
value : match[0]
|
value : match[0]
|
||||||
}
|
};
|
||||||
|
|
||||||
if (re.lastIndex == lastIndex) { throw new Error("tokenizer error") }
|
if (re.lastIndex == lastIndex) { throw new Error("tokenizer error"); }
|
||||||
lastIndex = re.lastIndex;
|
lastIndex = re.lastIndex;
|
||||||
|
|
||||||
// console.log(match);
|
// console.log(match);
|
||||||
|
|
@ -71,5 +71,5 @@ ace.Tokenizer.prototype.getLineTokens = function(line, startState) {
|
||||||
return {
|
return {
|
||||||
tokens : tokens,
|
tokens : tokens,
|
||||||
state : currentState
|
state : currentState
|
||||||
}
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -32,7 +32,7 @@ ace.VirtualRenderer = function(container) {
|
||||||
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;
|
||||||
|
|
@ -63,7 +63,7 @@ ace.VirtualRenderer.prototype.updateLines = function(firstRow, lastRow) {
|
||||||
|
|
||||||
// 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,7 +108,7 @@ ace.VirtualRenderer.prototype.draw = function() {
|
||||||
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";
|
||||||
this.gutterLayer.update(layerConfig);
|
this.gutterLayer.update(layerConfig);
|
||||||
}
|
};
|
||||||
|
|
||||||
ace.VirtualRenderer.prototype.addMarker = function(range, clazz) {
|
ace.VirtualRenderer.prototype.addMarker = function(range, clazz) {
|
||||||
return this.markerLayer.addMarker(range, clazz);
|
return this.markerLayer.addMarker(range, clazz);
|
||||||
|
|
@ -134,7 +134,7 @@ ace.VirtualRenderer.prototype.showCursor = function() {
|
||||||
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;
|
||||||
var top = pos.top;
|
var top = pos.top;
|
||||||
|
|
||||||
if (this.getScrollTop() > top) {
|
if (this.getScrollTop() > top) {
|
||||||
|
|
@ -163,7 +163,7 @@ 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
|
||||||
|
|
@ -187,7 +187,7 @@ ace.VirtualRenderer.prototype.screenToTextCoordinates = function(pageX, pageY) {
|
||||||
return {
|
return {
|
||||||
row : row,
|
row : row,
|
||||||
column : col
|
column : col
|
||||||
}
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.VirtualRenderer.prototype.visualizeFocus = function() {
|
ace.VirtualRenderer.prototype.visualizeFocus = function() {
|
||||||
|
|
|
||||||
296
src/lib.js
296
src/lib.js
|
|
@ -3,157 +3,157 @@ if (!window.ace)
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
ace.addListener = function(elem, type, callback) {
|
ace.addListener = function(elem, type, callback) {
|
||||||
if (elem.addEventListener) { return elem.addEventListener(type,
|
if (elem.addEventListener) { return elem.addEventListener(type,
|
||||||
callback,
|
callback,
|
||||||
false); }
|
false); }
|
||||||
if (elem.attachEvent) {
|
if (elem.attachEvent) {
|
||||||
var wrapper = function() {
|
var wrapper = function() {
|
||||||
callback(window.event);
|
callback(window.event);
|
||||||
|
};
|
||||||
|
callback.$$wrapper = wrapper;
|
||||||
|
elem.attachEvent("on" + type, wrapper);
|
||||||
}
|
}
|
||||||
callback.$$wrapper = wrapper;
|
|
||||||
elem.attachEvent("on" + type, wrapper);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ace.removeListener = function(elem, type, callback) {
|
|
||||||
if (elem.removeEventListener) { return elem
|
|
||||||
.removeEventListener(type, callback, false); }
|
|
||||||
if (elem.detachEvent) {
|
|
||||||
elem.detachEvent("on" + type, callback.$$wrapper || callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ace.setText = function(elem, text) {
|
|
||||||
if (elem.innerText !== undefined) {
|
|
||||||
elem.innerText = text;
|
|
||||||
}
|
|
||||||
if (elem.textContent !== undefined) {
|
|
||||||
elem.textContent = text;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ace.stopEvent = function(e) {
|
|
||||||
ace.stopPropagation(e);
|
|
||||||
ace.preventDefault(e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ace.stopPropagation = function(e) {
|
|
||||||
if (e.stopPropagation)
|
|
||||||
e.stopPropagation();
|
|
||||||
else
|
|
||||||
e.cancelBubble = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
ace.preventDefault = function(e) {
|
|
||||||
if (e.preventDefault)
|
|
||||||
e.preventDefault();
|
|
||||||
else
|
|
||||||
e.returnValue = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ace.inherits = function(ctor, superCtor) {
|
|
||||||
var tempCtor = function() {
|
|
||||||
};
|
|
||||||
tempCtor.prototype = superCtor.prototype;
|
|
||||||
ctor.super_ = superCtor.prototype;
|
|
||||||
ctor.prototype = new tempCtor();
|
|
||||||
ctor.prototype.constructor = ctor;
|
|
||||||
};
|
|
||||||
|
|
||||||
ace.getInnerWidth = function(element) {
|
|
||||||
return (parseInt(ace.computedStyle(element, "paddingLeft"))
|
|
||||||
+ parseInt(ace.computedStyle(element, "paddingRight")) + element.clientWidth);
|
|
||||||
};
|
|
||||||
|
|
||||||
ace.getInnerHeight = function(element) {
|
|
||||||
return (parseInt(ace.computedStyle(element, "paddingTop"))
|
|
||||||
+ parseInt(ace.computedStyle(element, "paddingBottom")) + element.clientHeight);
|
|
||||||
};
|
|
||||||
|
|
||||||
ace.computedStyle = function(element, style) {
|
|
||||||
if (window.getComputedStyle) {
|
|
||||||
return (window.getComputedStyle(element, null))[style];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return element.currentStyle[style];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ace.scrollbarHeight = function() {
|
|
||||||
var el = document.createElement("div");
|
|
||||||
var style = el.style;
|
|
||||||
|
|
||||||
style.position = "absolute";
|
|
||||||
style.left = "-10000px";
|
|
||||||
style.overflow = "scroll";
|
|
||||||
style.height = "100px";
|
|
||||||
|
|
||||||
document.body.appendChild(el);
|
|
||||||
var height = el.offsetHeight - el.clientHeight;
|
|
||||||
document.body.removeChild(el);
|
|
||||||
|
|
||||||
return height;
|
|
||||||
}
|
|
||||||
|
|
||||||
ace.bind = function(fcn, context) {
|
|
||||||
return function() {
|
|
||||||
return fcn.apply(context, arguments);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ace.capture = function(el, eventHandler, releaseCaptureHandler) {
|
|
||||||
function onMouseMove(e) {
|
|
||||||
eventHandler(e);
|
|
||||||
e.stopPropagation();
|
|
||||||
}
|
|
||||||
|
|
||||||
function onMouseUp(e) {
|
|
||||||
eventHandler && eventHandler(e);
|
|
||||||
releaseCaptureHandler && releaseCaptureHandler();
|
|
||||||
|
|
||||||
document.removeEventListener("mousemove", onMouseMove, true);
|
|
||||||
document.removeEventListener("mouseup", onMouseUp, true);
|
|
||||||
|
|
||||||
e.stopPropagation();
|
|
||||||
}
|
|
||||||
|
|
||||||
document.addEventListener("mousemove", onMouseMove, true);
|
|
||||||
document.addEventListener("mouseup", onMouseUp, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
ace.addMouseWheelListener = function(el, callback) {
|
|
||||||
var listener = function(e) {
|
|
||||||
e.wheel = (e.wheelDelta) ? e.wheelDelta / 120
|
|
||||||
: -(e.detail || 0) / 3;
|
|
||||||
callback(e);
|
|
||||||
}
|
|
||||||
ace.addListener(el, "DOMMouseScroll", listener);
|
|
||||||
ace.addListener(el, "mousewheel", listener);
|
|
||||||
};
|
|
||||||
|
|
||||||
ace.autoremoveListener = function(el, type, callback, timeout) {
|
|
||||||
var listener = function(e) {
|
|
||||||
clearTimeout(timeoutId);
|
|
||||||
remove();
|
|
||||||
callback(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
var remove = function() {
|
|
||||||
ace.removeListener(el, type, listener);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ace.addListener(el, type, listener);
|
ace.removeListener = function(elem, type, callback) {
|
||||||
var timeoutId = setTimeout(remove, timeout);
|
if (elem.removeEventListener) { return elem
|
||||||
}
|
.removeEventListener(type, callback, false); }
|
||||||
|
if (elem.detachEvent) {
|
||||||
|
elem.detachEvent("on" + type, callback.$$wrapper || callback);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
ace.addTripleClickListener = function(el, callback) {
|
ace.setText = function(elem, text) {
|
||||||
ace.addListener(el, "mousedown", function() {
|
if (elem.innerText !== undefined) {
|
||||||
ace.autoremoveListener(el, "mousedown", function() {
|
elem.innerText = text;
|
||||||
ace.autoremoveListener(el, "mousedown", callback, 300);
|
}
|
||||||
}, 300);
|
if (elem.textContent !== undefined) {
|
||||||
});
|
elem.textContent = text;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.stopEvent = function(e) {
|
||||||
|
ace.stopPropagation(e);
|
||||||
|
ace.preventDefault(e);
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.stopPropagation = function(e) {
|
||||||
|
if (e.stopPropagation)
|
||||||
|
e.stopPropagation();
|
||||||
|
else
|
||||||
|
e.cancelBubble = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.preventDefault = function(e) {
|
||||||
|
if (e.preventDefault)
|
||||||
|
e.preventDefault();
|
||||||
|
else
|
||||||
|
e.returnValue = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.inherits = function(ctor, superCtor) {
|
||||||
|
var tempCtor = function() {
|
||||||
|
};
|
||||||
|
tempCtor.prototype = superCtor.prototype;
|
||||||
|
ctor.super_ = superCtor.prototype;
|
||||||
|
ctor.prototype = new tempCtor();
|
||||||
|
ctor.prototype.constructor = ctor;
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.getInnerWidth = function(element) {
|
||||||
|
return (parseInt(ace.computedStyle(element, "paddingLeft"))
|
||||||
|
+ parseInt(ace.computedStyle(element, "paddingRight")) + element.clientWidth);
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.getInnerHeight = function(element) {
|
||||||
|
return (parseInt(ace.computedStyle(element, "paddingTop"))
|
||||||
|
+ parseInt(ace.computedStyle(element, "paddingBottom")) + element.clientHeight);
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.computedStyle = function(element, style) {
|
||||||
|
if (window.getComputedStyle) {
|
||||||
|
return (window.getComputedStyle(element, null))[style];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return element.currentStyle[style];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.scrollbarHeight = function() {
|
||||||
|
var el = document.createElement("div");
|
||||||
|
var style = el.style;
|
||||||
|
|
||||||
|
style.position = "absolute";
|
||||||
|
style.left = "-10000px";
|
||||||
|
style.overflow = "scroll";
|
||||||
|
style.height = "100px";
|
||||||
|
|
||||||
|
document.body.appendChild(el);
|
||||||
|
var height = el.offsetHeight - el.clientHeight;
|
||||||
|
document.body.removeChild(el);
|
||||||
|
|
||||||
|
return height;
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.bind = function(fcn, context) {
|
||||||
|
return function() {
|
||||||
|
return fcn.apply(context, arguments);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.capture = function(el, eventHandler, releaseCaptureHandler) {
|
||||||
|
function onMouseMove(e) {
|
||||||
|
eventHandler(e);
|
||||||
|
e.stopPropagation();
|
||||||
|
}
|
||||||
|
|
||||||
|
function onMouseUp(e) {
|
||||||
|
eventHandler && eventHandler(e);
|
||||||
|
releaseCaptureHandler && releaseCaptureHandler();
|
||||||
|
|
||||||
|
document.removeEventListener("mousemove", onMouseMove, true);
|
||||||
|
document.removeEventListener("mouseup", onMouseUp, true);
|
||||||
|
|
||||||
|
e.stopPropagation();
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener("mousemove", onMouseMove, true);
|
||||||
|
document.addEventListener("mouseup", onMouseUp, true);
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.addMouseWheelListener = function(el, callback) {
|
||||||
|
var listener = function(e) {
|
||||||
|
e.wheel = (e.wheelDelta) ? e.wheelDelta / 120
|
||||||
|
: -(e.detail || 0) / 3;
|
||||||
|
callback(e);
|
||||||
|
};
|
||||||
|
ace.addListener(el, "DOMMouseScroll", listener);
|
||||||
|
ace.addListener(el, "mousewheel", listener);
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.autoremoveListener = function(el, type, callback, timeout) {
|
||||||
|
var listener = function(e) {
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
remove();
|
||||||
|
callback(e);
|
||||||
|
};
|
||||||
|
|
||||||
|
var remove = function() {
|
||||||
|
ace.removeListener(el, type, listener);
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.addListener(el, type, listener);
|
||||||
|
var timeoutId = setTimeout(remove, timeout);
|
||||||
|
};
|
||||||
|
|
||||||
|
ace.addTripleClickListener = function(el, callback) {
|
||||||
|
ace.addListener(el, "mousedown", function() {
|
||||||
|
ace.autoremoveListener(el, "mousedown", function() {
|
||||||
|
ace.autoremoveListener(el, "mousedown", callback, 300);
|
||||||
|
}, 300);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
MockRenderer = function() {
|
MockRenderer = function() {
|
||||||
this.container = document.createElement("div");
|
this.container = document.createElement("div");
|
||||||
this.cursor = {
|
this.cursor = {
|
||||||
row: 0,
|
row : 0,
|
||||||
column: 0
|
column : 0
|
||||||
}
|
};
|
||||||
|
|
||||||
this.visibleRowCount = 20;
|
this.visibleRowCount = 20;
|
||||||
|
|
||||||
this.layerConfig = {
|
this.layerConfig = {
|
||||||
firstVisibleRow: 0,
|
firstVisibleRow : 0,
|
||||||
lastVisibleRow: this.visibleRowCount,
|
lastVisibleRow : this.visibleRowCount
|
||||||
}
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -41,18 +41,22 @@ MockRenderer.prototype.updateCursor = function(position) {
|
||||||
MockRenderer.prototype.scrollCursorIntoView = function() {
|
MockRenderer.prototype.scrollCursorIntoView = function() {
|
||||||
if (this.cursor.row < this.layerConfig.firstVisibleRow) {
|
if (this.cursor.row < this.layerConfig.firstVisibleRow) {
|
||||||
this.scrollToRow(this.cursor.row);
|
this.scrollToRow(this.cursor.row);
|
||||||
} else if (this.cursor.row > this.layerConfig.lastVisibleRow) {
|
}
|
||||||
|
else if (this.cursor.row > this.layerConfig.lastVisibleRow) {
|
||||||
this.scrollToRow(this.cursor.row);
|
this.scrollToRow(this.cursor.row);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
MockRenderer.prototype.scrollToRow = function(row) {
|
MockRenderer.prototype.scrollToRow = function(row) {
|
||||||
var row = Math.min(this.lines.length - this.visibleRowCount, Math.max(0, row));
|
var row = Math.min(this.lines.length - this.visibleRowCount, Math.max(0,
|
||||||
|
row));
|
||||||
this.layerConfig.firstVisibleRow = row;
|
this.layerConfig.firstVisibleRow = row;
|
||||||
this.layerConfig.lastVisibleRow = row + this.visibleRowCount;
|
this.layerConfig.lastVisibleRow = row + this.visibleRowCount;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
MockRenderer.prototype.draw = function() {
|
MockRenderer.prototype.draw = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
MockRenderer.prototype.addMarker = function() {
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -47,5 +47,37 @@ var NavigationTest = TestCase("NavigationTest", {
|
||||||
editor.navigateFileStart();
|
editor.navigateFileStart();
|
||||||
|
|
||||||
assertEquals(0, editor.getFirstVisibleRow());
|
assertEquals(0, editor.getFirstVisibleRow());
|
||||||
|
},
|
||||||
|
|
||||||
|
"test: move selection lead to end of file" : function() {
|
||||||
|
var editor = new ace.Editor(this.createTextDocument(200, 10),
|
||||||
|
new MockRenderer());
|
||||||
|
|
||||||
|
editor.moveCursorTo(100, 5);
|
||||||
|
editor.selectFileEnd();
|
||||||
|
|
||||||
|
var selection = editor.getSelectionRange();
|
||||||
|
|
||||||
|
assertEquals(100, selection.start.row);
|
||||||
|
assertEquals(5, selection.start.column);
|
||||||
|
|
||||||
|
assertEquals(199, selection.end.row);
|
||||||
|
assertEquals(10, selection.end.column);
|
||||||
|
},
|
||||||
|
|
||||||
|
"test: move selection lead to start of file" : function() {
|
||||||
|
var editor = new ace.Editor(this.createTextDocument(200, 10),
|
||||||
|
new MockRenderer());
|
||||||
|
|
||||||
|
editor.moveCursorTo(100, 5);
|
||||||
|
editor.selectFileStart();
|
||||||
|
|
||||||
|
var selection = editor.getSelectionRange();
|
||||||
|
|
||||||
|
assertEquals(0, selection.start.row);
|
||||||
|
assertEquals(0, selection.start.column);
|
||||||
|
|
||||||
|
assertEquals(100, selection.end.row);
|
||||||
|
assertEquals(5, selection.end.column);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue