introduce "ace" namespace and unify OO style
This commit is contained in:
parent
72b556efaa
commit
84ec636d7d
16 changed files with 835 additions and 813 deletions
|
|
@ -40,7 +40,8 @@
|
|||
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
|
||||
var editor = new Editor(new TextDocument("Juhu Kinners"), new VirtualRenderer("container"));
|
||||
var container = document.getElementById("container");
|
||||
var editor = new ace.Editor(new ace.TextDocument("Juhu Kinners"), new ace.VirtualRenderer(container));
|
||||
|
||||
window.onresize = function() {
|
||||
editor.resize();
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ button.onclick = function()
|
|||
console.log("update", firstLine, lastLine);
|
||||
};
|
||||
|
||||
var tokenizer = new BackgroundTokenizer(new Tokenizer(JavaScript.RULES), onUpdate, onComplete);
|
||||
var tokenizer = new ace.BackgroundTokenizer(new ace.Tokenizer(ace.JavaScript.RULES), onUpdate, onComplete);
|
||||
tokenizer.setLines(text.value.split(/[\n\r]/));
|
||||
tokenizer.start();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,11 +14,11 @@
|
|||
Juhu Kinners
|
||||
</div>
|
||||
|
||||
<script src="../src/lib.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="../src/ace.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
|
||||
var el = document.getElementById("juhu");
|
||||
lib.addTripleClickListener(el, function() {
|
||||
ace.addTripleClickListener(el, function() {
|
||||
console.log("triple");
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
function BackgroundTokenizer(tokenizer, onUpdate, onComplete)
|
||||
if (!window.ace) ace = {};
|
||||
|
||||
ace.BackgroundTokenizer = function(tokenizer, onUpdate, onComplete)
|
||||
{
|
||||
this.running = false;
|
||||
this.textLines = [];
|
||||
|
|
@ -47,7 +49,7 @@ function BackgroundTokenizer(tokenizer, onUpdate, onComplete)
|
|||
}
|
||||
};
|
||||
|
||||
BackgroundTokenizer.prototype.setLines = function(textLines)
|
||||
ace.BackgroundTokenizer.prototype.setLines = function(textLines)
|
||||
{
|
||||
this.textLines = textLines;
|
||||
this.lines = [];
|
||||
|
|
@ -55,7 +57,7 @@ BackgroundTokenizer.prototype.setLines = function(textLines)
|
|||
this.stop();
|
||||
};
|
||||
|
||||
BackgroundTokenizer.prototype.start = function(startRow)
|
||||
ace.BackgroundTokenizer.prototype.start = function(startRow)
|
||||
{
|
||||
this.currentLine = Math.min(startRow || 0, this.currentLine, this.textLines.length);
|
||||
this.lines.splice(startRow, this.lines.length);
|
||||
|
|
@ -67,11 +69,11 @@ BackgroundTokenizer.prototype.start = function(startRow)
|
|||
}
|
||||
};
|
||||
|
||||
BackgroundTokenizer.prototype.stop = function() {
|
||||
ace.BackgroundTokenizer.prototype.stop = function() {
|
||||
this.running = false;
|
||||
};
|
||||
|
||||
BackgroundTokenizer.prototype.getTokens = function(row)
|
||||
ace.BackgroundTokenizer.prototype.getTokens = function(row)
|
||||
{
|
||||
if (this.lines[row]) {
|
||||
return this.lines[row].tokens;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
function CursorLayer(parentEl)
|
||||
if (!window.ace) ace = {};
|
||||
|
||||
ace.CursorLayer = function(parentEl)
|
||||
{
|
||||
this.element = document.createElement("div");
|
||||
this.element.className = "layer cursor-layer";
|
||||
|
|
@ -10,7 +12,7 @@ function CursorLayer(parentEl)
|
|||
this.isVisible = false;
|
||||
}
|
||||
|
||||
CursorLayer.prototype.setCursor = function(position)
|
||||
ace.CursorLayer.prototype.setCursor = function(position)
|
||||
{
|
||||
this.position = {
|
||||
row: position.row,
|
||||
|
|
@ -18,7 +20,7 @@ CursorLayer.prototype.setCursor = function(position)
|
|||
};
|
||||
};
|
||||
|
||||
CursorLayer.prototype.hideCursor = function()
|
||||
ace.CursorLayer.prototype.hideCursor = function()
|
||||
{
|
||||
this.isVisible = false;
|
||||
if (this.cursor.parentNode) {
|
||||
|
|
@ -27,7 +29,7 @@ CursorLayer.prototype.hideCursor = function()
|
|||
clearInterval(this.blinkId);
|
||||
};
|
||||
|
||||
CursorLayer.prototype.showCursor = function()
|
||||
ace.CursorLayer.prototype.showCursor = function()
|
||||
{
|
||||
this.isVisible = true;
|
||||
this.element.appendChild(this.cursor);
|
||||
|
|
@ -43,11 +45,11 @@ CursorLayer.prototype.showCursor = function()
|
|||
}, 1000);
|
||||
};
|
||||
|
||||
CursorLayer.prototype.getPixelPosition = function() {
|
||||
ace.CursorLayer.prototype.getPixelPosition = function() {
|
||||
return this.pixelPos || {left: 0, top:0};
|
||||
}
|
||||
|
||||
CursorLayer.prototype.update = function(config)
|
||||
ace.CursorLayer.prototype.update = function(config)
|
||||
{
|
||||
if (!this.position) return;
|
||||
|
||||
|
|
|
|||
327
src/Editor.js
327
src/Editor.js
|
|
@ -1,3 +1,7 @@
|
|||
if (!window.ace) ace = {};
|
||||
|
||||
(function() {
|
||||
|
||||
var keys = {
|
||||
UP: 38,
|
||||
RIGHT: 39,
|
||||
|
|
@ -13,9 +17,9 @@ var keys = {
|
|||
A: 65
|
||||
}
|
||||
|
||||
function KeyBinding(element, host)
|
||||
var KeyBinding = function(element, host)
|
||||
{
|
||||
lib.addListener(element, "keydown", function(e)
|
||||
ace.addListener(element, "keydown", function(e)
|
||||
{
|
||||
var key = e.keyCode;
|
||||
|
||||
|
|
@ -25,7 +29,7 @@ function KeyBinding(element, host)
|
|||
if (e.metaKey)
|
||||
{
|
||||
host.selectAll();
|
||||
return lib.stopEvent(e);
|
||||
return ace.stopEvent(e);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -35,7 +39,7 @@ function KeyBinding(element, host)
|
|||
} else {
|
||||
host.navigateUp();
|
||||
}
|
||||
return lib.stopEvent(e);
|
||||
return ace.stopEvent(e);
|
||||
|
||||
case keys.DOWN:
|
||||
if (e.shiftKey) {
|
||||
|
|
@ -43,7 +47,7 @@ function KeyBinding(element, host)
|
|||
} else {
|
||||
host.navigateDown();
|
||||
}
|
||||
return lib.stopEvent(e);
|
||||
return ace.stopEvent(e);
|
||||
|
||||
case keys.LEFT:
|
||||
if (e.metaKey && e.shiftKey) {
|
||||
|
|
@ -55,7 +59,7 @@ function KeyBinding(element, host)
|
|||
} else {
|
||||
host.navigateLeft();
|
||||
}
|
||||
return lib.stopEvent(e);
|
||||
return ace.stopEvent(e);
|
||||
|
||||
case keys.RIGHT:
|
||||
if (e.metaKey && e.shiftKey) {
|
||||
|
|
@ -67,7 +71,7 @@ function KeyBinding(element, host)
|
|||
} else {
|
||||
host.navigateRight();
|
||||
}
|
||||
return lib.stopEvent(e);
|
||||
return ace.stopEvent(e);
|
||||
|
||||
case keys.PAGEDOWN:
|
||||
if (e.shiftKey) {
|
||||
|
|
@ -75,7 +79,7 @@ function KeyBinding(element, host)
|
|||
} else {
|
||||
host.scrollPageDown();
|
||||
}
|
||||
return lib.stopEvent(e);
|
||||
return ace.stopEvent(e);
|
||||
|
||||
case keys.PAGEUP:
|
||||
if (e.shiftKey) {
|
||||
|
|
@ -83,7 +87,7 @@ function KeyBinding(element, host)
|
|||
} else {
|
||||
host.scrollPageUp();
|
||||
}
|
||||
return lib.stopEvent(e);
|
||||
return ace.stopEvent(e);
|
||||
|
||||
case keys.POS1:
|
||||
if (e.shiftKey) {
|
||||
|
|
@ -91,7 +95,7 @@ function KeyBinding(element, host)
|
|||
} else {
|
||||
host.navigateLineStart();
|
||||
}
|
||||
return lib.stopEvent(e);
|
||||
return ace.stopEvent(e);
|
||||
|
||||
case keys.END:
|
||||
if (e.shiftKey) {
|
||||
|
|
@ -99,43 +103,43 @@ function KeyBinding(element, host)
|
|||
} else {
|
||||
host.navigateLineEnd();
|
||||
}
|
||||
return lib.stopEvent(e);
|
||||
return ace.stopEvent(e);
|
||||
|
||||
case keys.DELETE:
|
||||
host.removeRight();
|
||||
return lib.stopEvent(e);
|
||||
return ace.stopEvent(e);
|
||||
|
||||
case keys.BACKSPACE:
|
||||
host.removeLeft();
|
||||
return lib.stopEvent(e);
|
||||
return ace.stopEvent(e);
|
||||
|
||||
case keys.TAB:
|
||||
host.onTextInput(" ");
|
||||
return lib.stopEvent(e);
|
||||
return ace.stopEvent(e);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function Editor(doc, renderer)
|
||||
ace.Editor = function(doc, renderer)
|
||||
{
|
||||
var container = renderer.getContainerElement();
|
||||
this.renderer = renderer;
|
||||
|
||||
this.textInput = new TextInput(container, this);
|
||||
this.textInput = new ace.TextInput(container, this);
|
||||
new KeyBinding(container, this);
|
||||
|
||||
lib.addListener(container, "mousedown", lib.bind(this.onMouseDown, this));
|
||||
lib.addListener(container, "dblclick", lib.bind(this.onMouseDoubleClick, this));
|
||||
lib.addMouseWheelListener(container, lib.bind(this.onMouseWheel, this));
|
||||
lib.addTripleClickListener(container, lib.bind(this.selectCurrentLine, this));
|
||||
ace.addListener(container, "mousedown", ace.bind(this.onMouseDown, this));
|
||||
ace.addListener(container, "dblclick", ace.bind(this.onMouseDoubleClick, this));
|
||||
ace.addMouseWheelListener(container, ace.bind(this.onMouseWheel, this));
|
||||
ace.addTripleClickListener(container, ace.bind(this.selectCurrentLine, this));
|
||||
|
||||
this.doc = doc;
|
||||
doc.addChangeListener(lib.bind(this.onDocumentChange, this));
|
||||
doc.addChangeListener(ace.bind(this.onDocumentChange, this));
|
||||
renderer.setDocument(doc);
|
||||
|
||||
this.tokenizer = new BackgroundTokenizer(
|
||||
new Tokenizer(XML.RULES),
|
||||
lib.bind(this.onTokenizerUpdate, this)
|
||||
this.tokenizer = new ace.BackgroundTokenizer(
|
||||
new ace.Tokenizer(ace.XML.RULES),
|
||||
ace.bind(this.onTokenizerUpdate, this)
|
||||
);
|
||||
|
||||
this.tokenizer.setLines(doc.lines);
|
||||
|
|
@ -151,40 +155,38 @@ function Editor(doc, renderer)
|
|||
this.selection = null;
|
||||
|
||||
this.renderer.draw();
|
||||
}
|
||||
};
|
||||
|
||||
Editor.prototype =
|
||||
{
|
||||
resize : function() {
|
||||
ace.Editor.prototype.resize = function() {
|
||||
this.renderer.draw();
|
||||
},
|
||||
};
|
||||
|
||||
updateCursor : function() {
|
||||
ace.Editor.prototype.updateCursor = function() {
|
||||
this.renderer.updateCursor(this.cursor);
|
||||
},
|
||||
};
|
||||
|
||||
onFocus : function() {
|
||||
ace.Editor.prototype.onFocus = function() {
|
||||
this.renderer.showCursor();
|
||||
this.renderer.visualizeFocus();
|
||||
},
|
||||
};
|
||||
|
||||
onBlur : function() {
|
||||
ace.Editor.prototype.onBlur = function() {
|
||||
this.renderer.hideCursor();
|
||||
this.renderer.visualizeBlur();
|
||||
},
|
||||
};
|
||||
|
||||
onDocumentChange : function(startRow, endRow)
|
||||
{
|
||||
ace.Editor.prototype.onDocumentChange = function(startRow, endRow)
|
||||
{
|
||||
this.tokenizer.start(startRow);
|
||||
this.renderer.updateLines(startRow, endRow);
|
||||
},
|
||||
};
|
||||
|
||||
onTokenizerUpdate : function(startRow, endRow) {
|
||||
ace.Editor.prototype.onTokenizerUpdate = function(startRow, endRow) {
|
||||
this.renderer.updateLines(startRow, endRow);
|
||||
},
|
||||
};
|
||||
|
||||
onMouseDown : function(e)
|
||||
{
|
||||
ace.Editor.prototype.onMouseDown = function(e)
|
||||
{
|
||||
this.textInput.focus();
|
||||
|
||||
var pos = this.renderer.screenToTextCoordinates(e.pageX, e.pageY);
|
||||
|
|
@ -216,14 +218,14 @@ function Editor(doc, renderer)
|
|||
_self.renderer.scrollCursorIntoView();
|
||||
};
|
||||
|
||||
lib.capture(this.container, onMouseSelection, onMouseSelectionEnd);
|
||||
ace.capture(this.container, onMouseSelection, onMouseSelectionEnd);
|
||||
var timerId = setInterval(onSelectionInterval, 20 );
|
||||
|
||||
return lib.preventDefault(e);
|
||||
},
|
||||
return ace.preventDefault(e);
|
||||
};
|
||||
|
||||
onMouseDoubleClick : function(e)
|
||||
{
|
||||
ace.Editor.prototype.onMouseDoubleClick = function(e)
|
||||
{
|
||||
var line = this.doc.getLine(this.cursor.row);
|
||||
var column = this.cursor.column;
|
||||
|
||||
|
|
@ -259,36 +261,36 @@ function Editor(doc, renderer)
|
|||
this._moveSelection(function() {
|
||||
this.moveCursorTo(this.cursor.row, end);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
onMouseWheel : function(e)
|
||||
{
|
||||
ace.Editor.prototype.onMouseWheel = function(e)
|
||||
{
|
||||
var delta = e.wheel;
|
||||
this.renderer.scrollToY(this.renderer.getScrollTop() - (delta * 15));
|
||||
return lib.preventDefault(e);
|
||||
},
|
||||
return ace.preventDefault(e);
|
||||
};
|
||||
|
||||
getCopyText : function()
|
||||
{
|
||||
ace.Editor.prototype.getCopyText = function()
|
||||
{
|
||||
if (this.hasSelection()) {
|
||||
return this.doc.getTextRange(this.getSelectionRange());
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
onCut : function()
|
||||
{
|
||||
ace.Editor.prototype.onCut = function()
|
||||
{
|
||||
if (this.hasSelection())
|
||||
{
|
||||
this.cursor = this.doc.remove(this.getSelectionRange());
|
||||
this.clearSelection();
|
||||
this.renderer.updateCursor(this.cursor);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
onTextInput: function(text)
|
||||
{
|
||||
ace.Editor.prototype.onTextInput = function(text)
|
||||
{
|
||||
if (this.hasSelection())
|
||||
{
|
||||
this.cursor = this.doc.replace(this.getSelectionRange(), text);
|
||||
|
|
@ -298,10 +300,10 @@ function Editor(doc, renderer)
|
|||
}
|
||||
this.renderer.updateCursor(this.cursor);
|
||||
this.renderer.scrollCursorIntoView();
|
||||
},
|
||||
};
|
||||
|
||||
removeRight : function()
|
||||
{
|
||||
ace.Editor.prototype.removeRight = function()
|
||||
{
|
||||
if (this.hasSelection())
|
||||
{
|
||||
this.cursor = this.doc.remove(this.getSelectionRange());
|
||||
|
|
@ -322,10 +324,10 @@ function Editor(doc, renderer)
|
|||
}
|
||||
|
||||
this.renderer.scrollCursorIntoView();
|
||||
},
|
||||
};
|
||||
|
||||
removeLeft : function()
|
||||
{
|
||||
ace.Editor.prototype.removeLeft = function()
|
||||
{
|
||||
if (this.hasSelection())
|
||||
{
|
||||
this.cursor = this.doc.remove(this.getSelectionRange());
|
||||
|
|
@ -351,66 +353,66 @@ function Editor(doc, renderer)
|
|||
|
||||
this.renderer.updateCursor(this.cursor);
|
||||
this.renderer.scrollCursorIntoView();
|
||||
},
|
||||
},
|
||||
|
||||
onCompositionStart : function()
|
||||
{
|
||||
ace.Editor.prototype.onCompositionStart = function()
|
||||
{
|
||||
this.renderer.showComposition(this.cursor);
|
||||
this.onTextInput(" ");
|
||||
},
|
||||
};
|
||||
|
||||
onCompositionUpdate : function(text) {
|
||||
ace.Editor.prototype.onCompositionUpdate = function(text) {
|
||||
this.renderer.setCompositionText(text);
|
||||
},
|
||||
};
|
||||
|
||||
onCompositionEnd : function() {
|
||||
ace.Editor.prototype.onCompositionEnd = function() {
|
||||
this.renderer.hideComposition();
|
||||
this.removeLeft();
|
||||
},
|
||||
};
|
||||
|
||||
getFirstVisibleRow : function() {
|
||||
ace.Editor.prototype.getFirstVisibleRow = function() {
|
||||
return this.renderer.getFirstVisibleRow();
|
||||
},
|
||||
};
|
||||
|
||||
getLastVisibleRow : function() {
|
||||
ace.Editor.prototype.getLastVisibleRow = function() {
|
||||
return this.renderer.getLastVisibleRow();
|
||||
},
|
||||
};
|
||||
|
||||
getPageDownRow : function() {
|
||||
ace.Editor.prototype.getPageDownRow = function() {
|
||||
return this.renderer.getLastVisibleRow() - 1;
|
||||
},
|
||||
};
|
||||
|
||||
getPageUpRow : function()
|
||||
{
|
||||
ace.Editor.prototype.getPageUpRow = function()
|
||||
{
|
||||
var firstRow = this.renderer.getFirstVisibleRow();
|
||||
var lastRow = this.renderer.getLastVisibleRow();
|
||||
|
||||
return firstRow - (lastRow-firstRow) + 1;
|
||||
},
|
||||
};
|
||||
|
||||
scrollPageDown : function() {
|
||||
ace.Editor.prototype.scrollPageDown = function() {
|
||||
this.renderer.scrollToRow(this.getPageDownRow());
|
||||
},
|
||||
};
|
||||
|
||||
scrollPageUp : function() {
|
||||
ace.Editor.prototype.scrollPageUp = function() {
|
||||
this.renderer.scrollToRow(this.getPageUpRow());
|
||||
},
|
||||
};
|
||||
|
||||
navigateUp : function()
|
||||
{
|
||||
ace.Editor.prototype.navigateUp = function()
|
||||
{
|
||||
this.clearSelection();
|
||||
this.moveCursorUp();
|
||||
this.renderer.scrollCursorIntoView();
|
||||
},
|
||||
};
|
||||
|
||||
navigateDown : function() {
|
||||
ace.Editor.prototype.navigateDown = function() {
|
||||
this.clearSelection();
|
||||
this.moveCursorDown();
|
||||
this.renderer.scrollCursorIntoView();
|
||||
},
|
||||
};
|
||||
|
||||
navigateLeft : function()
|
||||
{
|
||||
ace.Editor.prototype.navigateLeft = function()
|
||||
{
|
||||
if (this.hasSelection()) {
|
||||
var selectionStart = this.getSelectionRange().start;
|
||||
this.moveCursorTo(selectionStart.row, selectionStart.column);
|
||||
|
|
@ -420,10 +422,10 @@ function Editor(doc, renderer)
|
|||
this.clearSelection();
|
||||
|
||||
this.renderer.scrollCursorIntoView();
|
||||
},
|
||||
};
|
||||
|
||||
navigateRight : function()
|
||||
{
|
||||
ace.Editor.prototype.navigateRight = function()
|
||||
{
|
||||
if (this.hasSelection()) {
|
||||
var selectionEnd = this.getSelectionRange().end;
|
||||
this.moveCursorTo(selectionEnd.row, selectionEnd.column);
|
||||
|
|
@ -433,32 +435,32 @@ function Editor(doc, renderer)
|
|||
this.clearSelection();
|
||||
|
||||
this.renderer.scrollCursorIntoView();
|
||||
},
|
||||
},
|
||||
|
||||
navigateLineStart : function()
|
||||
{
|
||||
ace.Editor.prototype.navigateLineStart = function()
|
||||
{
|
||||
this.clearSelection();
|
||||
this.moveCursorLineStart();
|
||||
this.renderer.scrollCursorIntoView();
|
||||
},
|
||||
};
|
||||
|
||||
navigateLineEnd : function()
|
||||
{
|
||||
ace.Editor.prototype.navigateLineEnd = function()
|
||||
{
|
||||
this.clearSelection();
|
||||
this.moveCursorLineEnd();
|
||||
this.renderer.scrollCursorIntoView();
|
||||
},
|
||||
};
|
||||
|
||||
moveCursorUp : function() {
|
||||
ace.Editor.prototype.moveCursorUp = function() {
|
||||
this.moveCursorBy(-1, 0);
|
||||
},
|
||||
};
|
||||
|
||||
moveCursorDown : function() {
|
||||
ace.Editor.prototype.moveCursorDown = function() {
|
||||
this.moveCursorBy(1, 0);
|
||||
},
|
||||
};
|
||||
|
||||
moveCursorLeft : function()
|
||||
{
|
||||
ace.Editor.prototype.moveCursorLeft = function()
|
||||
{
|
||||
if (this.cursor.column == 0) {
|
||||
if (this.cursor.row > 0) {
|
||||
this.moveCursorTo(this.cursor.row-1, this.doc.getLine(this.cursor.row-1).length);
|
||||
|
|
@ -466,10 +468,10 @@ function Editor(doc, renderer)
|
|||
} else {
|
||||
this.moveCursorBy(0, -1);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
moveCursorRight : function()
|
||||
{
|
||||
ace.Editor.prototype.moveCursorRight = function()
|
||||
{
|
||||
if (this.cursor.column == this.doc.getLine(this.cursor.row).length) {
|
||||
if (this.cursor.row < this.doc.getLength()-1) {
|
||||
this.moveCursorTo(this.cursor.row+1, 0);
|
||||
|
|
@ -478,25 +480,25 @@ function Editor(doc, renderer)
|
|||
this.moveCursorBy(0, 1);
|
||||
}
|
||||
this.renderer.scrollCursorIntoView();
|
||||
},
|
||||
};
|
||||
|
||||
moveCursorLineStart : function()
|
||||
{
|
||||
ace.Editor.prototype.moveCursorLineStart = function()
|
||||
{
|
||||
this.moveCursorTo(this.cursor.row, 0);
|
||||
this.renderer.scrollCursorIntoView();
|
||||
},
|
||||
};
|
||||
|
||||
moveCursorLineEnd : function() {
|
||||
ace.Editor.prototype.moveCursorLineEnd = function() {
|
||||
this.moveCursorTo(this.cursor.row, this.doc.getLine(this.cursor.row).length);
|
||||
this.renderer.scrollCursorIntoView();
|
||||
},
|
||||
};
|
||||
|
||||
moveCursorBy : function(rows, chars) {
|
||||
ace.Editor.prototype.moveCursorBy = function(rows, chars) {
|
||||
this.moveCursorTo(this.cursor.row+rows, this.cursor.column+chars);
|
||||
},
|
||||
};
|
||||
|
||||
moveCursorTo : function(row, column)
|
||||
{
|
||||
ace.Editor.prototype.moveCursorTo = function(row, column)
|
||||
{
|
||||
if (row >= this.doc.getLength()) {
|
||||
this.cursor.row = this.doc.getLength()-1;
|
||||
this.cursor.column = this.doc.getLine(this.cursor.row).length;
|
||||
|
|
@ -508,14 +510,14 @@ function Editor(doc, renderer)
|
|||
this.cursor.column = Math.min(this.doc.getLine(this.cursor.row).length, Math.max(0, column));
|
||||
}
|
||||
this.updateCursor();
|
||||
},
|
||||
};
|
||||
|
||||
hasSelection : function() {
|
||||
ace.Editor.prototype.hasSelection = function() {
|
||||
return !!this.selectionLead;
|
||||
},
|
||||
};
|
||||
|
||||
setSelectionAnchor : function(row, column)
|
||||
{
|
||||
ace.Editor.prototype.setSelectionAnchor = function(row, column)
|
||||
{
|
||||
this.clearSelection();
|
||||
|
||||
this.selectionAnchor = {
|
||||
|
|
@ -524,10 +526,10 @@ function Editor(doc, renderer)
|
|||
};
|
||||
|
||||
this.selectionLead = null;
|
||||
},
|
||||
};
|
||||
|
||||
getSelectionRange : function()
|
||||
{
|
||||
ace.Editor.prototype.getSelectionRange = function()
|
||||
{
|
||||
var anchor = this.selectionAnchor;
|
||||
var lead = this.selectionLead;
|
||||
|
||||
|
|
@ -546,10 +548,10 @@ function Editor(doc, renderer)
|
|||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
clearSelection : function()
|
||||
{
|
||||
ace.Editor.prototype.clearSelection = function()
|
||||
{
|
||||
this.selectionLead = null;
|
||||
this.selectionAnchor = null;
|
||||
|
||||
|
|
@ -557,20 +559,20 @@ function Editor(doc, renderer)
|
|||
this.renderer.removeMarker(this.selection);
|
||||
this.selection = null;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
selectAll : function()
|
||||
{
|
||||
ace.Editor.prototype.selectAll = function()
|
||||
{
|
||||
var lastRow = this.doc.getLength()-1;
|
||||
this.setSelectionAnchor(lastRow, this.doc.getLine(lastRow).length);
|
||||
|
||||
this._moveSelection(function() {
|
||||
this.moveCursorTo(0, 0);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
_moveSelection : function(mover)
|
||||
{
|
||||
ace.Editor.prototype._moveSelection = function(mover)
|
||||
{
|
||||
if (!this.selectionAnchor) {
|
||||
this.selectionAnchor = {
|
||||
row: this.cursor.row,
|
||||
|
|
@ -590,34 +592,34 @@ function Editor(doc, renderer)
|
|||
}
|
||||
this.selection = this.renderer.addMarker(this.getSelectionRange(), "selection");
|
||||
this.renderer.scrollCursorIntoView();
|
||||
},
|
||||
};
|
||||
|
||||
selectUp : function() {
|
||||
ace.Editor.prototype.selectUp = function() {
|
||||
this._moveSelection(this.moveCursorUp);
|
||||
},
|
||||
};
|
||||
|
||||
selectDown : function() {
|
||||
ace.Editor.prototype.selectDown = function() {
|
||||
this._moveSelection(this.moveCursorDown);
|
||||
},
|
||||
};
|
||||
|
||||
selectRight : function() {
|
||||
ace.Editor.prototype.selectRight = function() {
|
||||
this._moveSelection(this.moveCursorRight);
|
||||
},
|
||||
};
|
||||
|
||||
selectLeft : function() {
|
||||
ace.Editor.prototype.selectLeft = function() {
|
||||
this._moveSelection(this.moveCursorLeft);
|
||||
},
|
||||
};
|
||||
|
||||
selectLineStart : function() {
|
||||
ace.Editor.prototype.selectLineStart = function() {
|
||||
this._moveSelection(this.moveCursorLineStart);
|
||||
},
|
||||
};
|
||||
|
||||
selectLineEnd : function() {
|
||||
ace.Editor.prototype.selectLineEnd = function() {
|
||||
this._moveSelection(this.moveCursorLineEnd);
|
||||
},
|
||||
};
|
||||
|
||||
selectPageDown : function()
|
||||
{
|
||||
ace.Editor.prototype.selectPageDown = function()
|
||||
{
|
||||
var visibleRows = this.getLastVisibleRow() - this.getFirstVisibleRow();
|
||||
var row = this.getPageDownRow() + Math.round(visibleRows / 2);
|
||||
|
||||
|
|
@ -626,10 +628,10 @@ function Editor(doc, renderer)
|
|||
this._moveSelection(function() {
|
||||
this.moveCursorTo(row, this.cursor.column);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
selectPageUp : function()
|
||||
{
|
||||
ace.Editor.prototype.selectPageUp = function()
|
||||
{
|
||||
var visibleRows = this.getLastVisibleRow() - this.getFirstVisibleRow();
|
||||
var row = this.getPageUpRow() + Math.round(visibleRows / 2);
|
||||
|
||||
|
|
@ -638,13 +640,14 @@ function Editor(doc, renderer)
|
|||
this._moveSelection(function() {
|
||||
this.moveCursorTo(row, this.cursor.column);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
selectCurrentLine : function()
|
||||
{
|
||||
ace.Editor.prototype.selectCurrentLine = function()
|
||||
{
|
||||
this.setSelectionAnchor(this.cursor.row, 0);
|
||||
this._moveSelection(function() {
|
||||
this.moveCursorTo(this.cursor.row+1, 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
@ -1,11 +1,13 @@
|
|||
function GutterLayer(parentEl)
|
||||
if (!window.ace) ace = {};
|
||||
|
||||
ace.GutterLayer = function(parentEl)
|
||||
{
|
||||
this.element = document.createElement("div");
|
||||
this.element.className = "layer gutter-layer";
|
||||
parentEl.appendChild(this.element);
|
||||
}
|
||||
|
||||
GutterLayer.prototype.update = function(config)
|
||||
ace.GutterLayer.prototype.update = function(config)
|
||||
{
|
||||
var html = [];
|
||||
for (var i=config.firstRow; i<=config.lastRow; i++)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
if (!window.ace) ace = {};
|
||||
|
||||
(function() {
|
||||
|
||||
window.JavaScript = {};
|
||||
ace.JavaScript = {};
|
||||
|
||||
var keywords = {
|
||||
"break" : 1,
|
||||
|
|
@ -31,7 +33,7 @@ var keywords = {
|
|||
// regexp must not have capturing parentheses
|
||||
// regexps are ordered -> the first match is used
|
||||
|
||||
JavaScript.RULES = {
|
||||
ace.JavaScript.RULES = {
|
||||
start :
|
||||
[
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
function MarkerLayer(parentEl)
|
||||
if (!window.ace) ace = {};
|
||||
|
||||
ace.MarkerLayer = function(parentEl)
|
||||
{
|
||||
this.element = document.createElement("div");
|
||||
this.element.className = "layer marker-layer";
|
||||
|
|
@ -8,7 +10,7 @@ function MarkerLayer(parentEl)
|
|||
this._markerId = 1;
|
||||
}
|
||||
|
||||
MarkerLayer.prototype.addMarker = function(range, clazz)
|
||||
ace.MarkerLayer.prototype.addMarker = function(range, clazz)
|
||||
{
|
||||
var id = this._markerId++;
|
||||
this.markers[id] = {
|
||||
|
|
@ -21,7 +23,7 @@ MarkerLayer.prototype.addMarker = function(range, clazz)
|
|||
return id;
|
||||
};
|
||||
|
||||
MarkerLayer.prototype.removeMarker = function(markerId)
|
||||
ace.MarkerLayer.prototype.removeMarker = function(markerId)
|
||||
{
|
||||
var marker = this.markers[markerId];
|
||||
if (marker) {
|
||||
|
|
@ -30,7 +32,7 @@ MarkerLayer.prototype.removeMarker = function(markerId)
|
|||
}
|
||||
};
|
||||
|
||||
MarkerLayer.prototype.update = function(config)
|
||||
ace.MarkerLayer.prototype.update = function(config)
|
||||
{
|
||||
var config = config || this.config;
|
||||
if (!config) return;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
function TextDocument(text)
|
||||
if (!window.ace) ace = {};
|
||||
|
||||
ace.TextDocument = function(text)
|
||||
{
|
||||
this.lines = this._split(text);
|
||||
this.modified = true;
|
||||
|
|
@ -6,25 +8,23 @@ function TextDocument(text)
|
|||
this.listeners = [];
|
||||
}
|
||||
|
||||
TextDocument.prototype =
|
||||
{
|
||||
_split : function(text) {
|
||||
ace.TextDocument.prototype._split = function(text) {
|
||||
return text.split(/[\n\r]/)
|
||||
},
|
||||
};
|
||||
|
||||
addChangeListener : function(listener) {
|
||||
ace.TextDocument.prototype.addChangeListener = function(listener) {
|
||||
this.listeners.push(listener);
|
||||
},
|
||||
};
|
||||
|
||||
fireChangeEvent : function(firstRow, lastRow)
|
||||
{
|
||||
ace.TextDocument.prototype.fireChangeEvent = function(firstRow, lastRow)
|
||||
{
|
||||
for (var i=0; i < this.listeners.length; i++) {
|
||||
this.listeners[i](firstRow, lastRow);
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
getWidth : function()
|
||||
{
|
||||
ace.TextDocument.prototype.getWidth = function()
|
||||
{
|
||||
if (this.modified)
|
||||
{
|
||||
this.modified = false;
|
||||
|
|
@ -37,13 +37,13 @@ TextDocument.prototype =
|
|||
this.width = longestLine;
|
||||
}
|
||||
return this.width;
|
||||
},
|
||||
};
|
||||
|
||||
getLine : function(row) {
|
||||
ace.TextDocument.prototype.getLine = function(row) {
|
||||
return this.lines[row] || "";
|
||||
},
|
||||
};
|
||||
|
||||
keywords : {
|
||||
ace.TextDocument.prototype.keywords = {
|
||||
"break" : 1,
|
||||
"case" : 1,
|
||||
"catch" : 1,
|
||||
|
|
@ -67,10 +67,10 @@ TextDocument.prototype =
|
|||
"var" : 1,
|
||||
"while" : 1,
|
||||
"with" : 1
|
||||
},
|
||||
};
|
||||
|
||||
getLineTokens : function(row)
|
||||
{
|
||||
ace.TextDocument.prototype.getLineTokens = function(row)
|
||||
{
|
||||
var tokens = [];
|
||||
|
||||
var re = /(?:(\s+)|("[^"]*")|('[^']*')|([\[\]\(\)\{\}])|([a-zA-Z_][a-zA-Z0-9_]*)|(\/\/.*)|(.))/g
|
||||
|
|
@ -97,14 +97,14 @@ TextDocument.prototype =
|
|||
};
|
||||
|
||||
return tokens;
|
||||
},
|
||||
};
|
||||
|
||||
getLength : function() {
|
||||
ace.TextDocument.prototype.getLength = function() {
|
||||
return this.lines.length;
|
||||
},
|
||||
};
|
||||
|
||||
getTextRange : function(range)
|
||||
{
|
||||
ace.TextDocument.prototype.getTextRange = function(range)
|
||||
{
|
||||
if (range.start.row == range.end.row) {
|
||||
return this.lines[range.start.row].substring(range.start.column, range.end.column);
|
||||
} else {
|
||||
|
|
@ -115,20 +115,20 @@ TextDocument.prototype =
|
|||
|
||||
return lines.join("\n");
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
insert : function(position, text)
|
||||
{
|
||||
ace.TextDocument.prototype.insert = function(position, text)
|
||||
{
|
||||
var end = this._insert(position, text);
|
||||
this.fireChangeEvent(
|
||||
position.row,
|
||||
position.row == end.row ? position.row : undefined
|
||||
);
|
||||
return end;
|
||||
},
|
||||
};
|
||||
|
||||
_insert : function(position, text)
|
||||
{
|
||||
ace.TextDocument.prototype._insert = function(position, text)
|
||||
{
|
||||
this.modified = true;
|
||||
|
||||
var newLines = this._split(text);
|
||||
|
|
@ -173,10 +173,10 @@ TextDocument.prototype =
|
|||
column: newLines[newLines.length-1].length
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
remove : function(range)
|
||||
{
|
||||
ace.TextDocument.prototype.remove = function(range)
|
||||
{
|
||||
var end = this._remove(range);
|
||||
|
||||
this.fireChangeEvent(
|
||||
|
|
@ -184,10 +184,10 @@ TextDocument.prototype =
|
|||
range.end.row == range.start.row ? range.start.row : undefined
|
||||
);
|
||||
return end;
|
||||
},
|
||||
};
|
||||
|
||||
_remove : function(range)
|
||||
{
|
||||
ace.TextDocument.prototype._remove = function(range)
|
||||
{
|
||||
this.modified = true;
|
||||
|
||||
var firstRow = range.start.row;
|
||||
|
|
@ -200,10 +200,10 @@ TextDocument.prototype =
|
|||
this.lines.splice(firstRow, lastRow-firstRow+1, row);
|
||||
|
||||
return range.start;
|
||||
},
|
||||
};
|
||||
|
||||
replace : function(range, text)
|
||||
{
|
||||
ace.TextDocument.prototype.replace = function(range, text)
|
||||
{
|
||||
this._remove(range);
|
||||
if (text) {
|
||||
var end = this._insert(range.start, text);
|
||||
|
|
@ -218,5 +218,4 @@ TextDocument.prototype =
|
|||
);
|
||||
|
||||
return end;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
function TextInput(parentNode, host) {
|
||||
if (!window.ace) ace = {};
|
||||
|
||||
ace.TextInput = function(parentNode, host) {
|
||||
|
||||
var text = document.createElement("textarea");
|
||||
var style = text.style;
|
||||
|
|
@ -51,23 +53,23 @@ function TextInput(parentNode, host) {
|
|||
text.select();
|
||||
}
|
||||
|
||||
lib.addListener(text, "keypress", onTextInput, false);
|
||||
lib.addListener(text, "textInput", onTextInput, false);
|
||||
lib.addListener(text, "paste", onTextInput, false);
|
||||
lib.addListener(text, "propertychange", onTextInput, false);
|
||||
ace.addListener(text, "keypress", onTextInput, false);
|
||||
ace.addListener(text, "textInput", onTextInput, false);
|
||||
ace.addListener(text, "paste", onTextInput, false);
|
||||
ace.addListener(text, "propertychange", onTextInput, false);
|
||||
|
||||
lib.addListener(text, "copy", onCopy, false);
|
||||
lib.addListener(text, "cut", onCut, false);
|
||||
ace.addListener(text, "copy", onCopy, false);
|
||||
ace.addListener(text, "cut", onCut, false);
|
||||
|
||||
lib.addListener(text, "compositionstart", onCompositionStart, false);
|
||||
lib.addListener(text, "compositionupdate", onCompositionUpdate, false);
|
||||
lib.addListener(text, "compositionend", onCompositionEnd, false);
|
||||
ace.addListener(text, "compositionstart", onCompositionStart, false);
|
||||
ace.addListener(text, "compositionupdate", onCompositionUpdate, false);
|
||||
ace.addListener(text, "compositionend", onCompositionEnd, false);
|
||||
|
||||
lib.addListener(text, "blur", function() {
|
||||
ace.addListener(text, "blur", function() {
|
||||
host.onBlur();
|
||||
}, false);
|
||||
|
||||
lib.addListener(text, "focus", function() {
|
||||
ace.addListener(text, "focus", function() {
|
||||
host.onFocus();
|
||||
}, false);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
function TextLayer(parentEl)
|
||||
if (!window.ace) ace = {};
|
||||
|
||||
ace.TextLayer = function(parentEl)
|
||||
{
|
||||
this.element = document.createElement("div");
|
||||
this.element.className = "layer text-layer";
|
||||
|
|
@ -7,19 +9,19 @@ function TextLayer(parentEl)
|
|||
this._measureSizes();
|
||||
}
|
||||
|
||||
TextLayer.prototype.setTokenizer = function(tokenizer) {
|
||||
ace.TextLayer.prototype.setTokenizer = function(tokenizer) {
|
||||
this.tokenizer = tokenizer;
|
||||
};
|
||||
|
||||
TextLayer.prototype.getLineHeight = function() {
|
||||
ace.TextLayer.prototype.getLineHeight = function() {
|
||||
return this.lineHeight;
|
||||
};
|
||||
|
||||
TextLayer.prototype.getCharacterWidth = function() {
|
||||
ace.TextLayer.prototype.getCharacterWidth = function() {
|
||||
return this.characterWidth;
|
||||
};
|
||||
|
||||
TextLayer.prototype._measureSizes = function()
|
||||
ace.TextLayer.prototype._measureSizes = function()
|
||||
{
|
||||
var measureNode = document.createElement("div");
|
||||
var style = measureNode.style;
|
||||
|
|
@ -41,7 +43,7 @@ TextLayer.prototype._measureSizes = function()
|
|||
this.element.removeChild(measureNode);
|
||||
};
|
||||
|
||||
TextLayer.prototype.updateLines = function(layerConfig, firstRow, lastRow)
|
||||
ace.TextLayer.prototype.updateLines = function(layerConfig, firstRow, lastRow)
|
||||
{
|
||||
var first = Math.max(firstRow, layerConfig.firstRow);
|
||||
var last = Math.min(lastRow, layerConfig.lastRow);
|
||||
|
|
@ -58,7 +60,7 @@ TextLayer.prototype.updateLines = function(layerConfig, firstRow, lastRow)
|
|||
};
|
||||
};
|
||||
|
||||
TextLayer.prototype.update = function(config)
|
||||
ace.TextLayer.prototype.update = function(config)
|
||||
{
|
||||
var html = [];
|
||||
for (var i=config.firstRow; i<=config.lastRow; i++)
|
||||
|
|
@ -76,7 +78,7 @@ TextLayer.prototype.update = function(config)
|
|||
this.element.innerHTML = html.join("");
|
||||
};
|
||||
|
||||
TextLayer.prototype.renderLine = function(stringBuilder, row)
|
||||
ace.TextLayer.prototype.renderLine = function(stringBuilder, row)
|
||||
{
|
||||
var tokens = this.tokenizer.getTokens(row);
|
||||
for (var i=0; i < tokens.length; i++)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
if (!window.ace) ace = {};
|
||||
|
||||
function Tokenizer(rules)
|
||||
ace.Tokenizer = function(rules)
|
||||
{
|
||||
this.rules = rules;
|
||||
|
||||
|
|
@ -17,7 +18,7 @@ function Tokenizer(rules)
|
|||
}
|
||||
};
|
||||
|
||||
Tokenizer.prototype.getLineTokens = function(line, startState)
|
||||
ace.Tokenizer.prototype.getLineTokens = function(line, startState)
|
||||
{
|
||||
var currentState = startState;
|
||||
var state = this.rules[currentState];
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
function VirtualRenderer(containerId)
|
||||
if (!window.ace) ace = {};
|
||||
|
||||
ace.VirtualRenderer = function(container)
|
||||
{
|
||||
this.container = document.getElementById(containerId);
|
||||
this.container = container;
|
||||
this.container.className += "editor";
|
||||
|
||||
this.scroller = document.createElement("div");
|
||||
|
|
@ -11,16 +13,16 @@ function VirtualRenderer(containerId)
|
|||
this.gutter.className = "gutter";
|
||||
this.container.appendChild(this.gutter);
|
||||
|
||||
this.gutterLayer = new GutterLayer(this.gutter);
|
||||
this.markerLayer = new MarkerLayer(this.scroller);
|
||||
this.gutterLayer = new ace.GutterLayer(this.gutter);
|
||||
this.markerLayer = new ace.MarkerLayer(this.scroller);
|
||||
|
||||
var textLayer = this.textLayer = new TextLayer(this.scroller);
|
||||
var textLayer = this.textLayer = new ace.TextLayer(this.scroller);
|
||||
this.canvas = textLayer.element;
|
||||
|
||||
this.characterWidth = textLayer.getCharacterWidth();
|
||||
this.lineHeight = textLayer.getLineHeight();
|
||||
|
||||
this.cursorLayer = new CursorLayer(this.scroller);
|
||||
this.cursorLayer = new ace.CursorLayer(this.scroller);
|
||||
|
||||
this.layers = [this.markerLayer, textLayer, this.cursorLayer];
|
||||
|
||||
|
|
@ -32,29 +34,29 @@ function VirtualRenderer(containerId)
|
|||
};
|
||||
}
|
||||
|
||||
VirtualRenderer.prototype.setDocument = function(doc)
|
||||
ace.VirtualRenderer.prototype.setDocument = function(doc)
|
||||
{
|
||||
this.lines = doc.lines;
|
||||
this.doc = doc;
|
||||
};
|
||||
|
||||
VirtualRenderer.prototype.setTokenizer = function(tokenizer) {
|
||||
ace.VirtualRenderer.prototype.setTokenizer = function(tokenizer) {
|
||||
this.textLayer.setTokenizer(tokenizer);
|
||||
};
|
||||
|
||||
VirtualRenderer.prototype.getContainerElement = function() {
|
||||
ace.VirtualRenderer.prototype.getContainerElement = function() {
|
||||
return this.container;
|
||||
};
|
||||
|
||||
VirtualRenderer.prototype.getFirstVisibleRow = function() {
|
||||
ace.VirtualRenderer.prototype.getFirstVisibleRow = function() {
|
||||
return this.layerConfig.firstRow || 0;
|
||||
};
|
||||
|
||||
VirtualRenderer.prototype.getLastVisibleRow = function() {
|
||||
ace.VirtualRenderer.prototype.getLastVisibleRow = function() {
|
||||
return this.layerConfig.lastRow || 0;
|
||||
};
|
||||
|
||||
VirtualRenderer.prototype.updateLines = function(firstRow, lastRow)
|
||||
ace.VirtualRenderer.prototype.updateLines = function(firstRow, lastRow)
|
||||
{
|
||||
var layerConfig = this.layerConfig;
|
||||
|
||||
|
|
@ -74,7 +76,7 @@ VirtualRenderer.prototype.updateLines = function(firstRow, lastRow)
|
|||
this.textLayer.updateLines(layerConfig, firstRow, lastRow);
|
||||
};
|
||||
|
||||
VirtualRenderer.prototype.draw = function()
|
||||
ace.VirtualRenderer.prototype.draw = function()
|
||||
{
|
||||
var lines = this.lines;
|
||||
|
||||
|
|
@ -115,29 +117,29 @@ VirtualRenderer.prototype.draw = function()
|
|||
this.gutterLayer.update(layerConfig);
|
||||
}
|
||||
|
||||
VirtualRenderer.prototype.addMarker = function(range, clazz) {
|
||||
ace.VirtualRenderer.prototype.addMarker = function(range, clazz) {
|
||||
return this.markerLayer.addMarker(range, clazz);
|
||||
};
|
||||
|
||||
VirtualRenderer.prototype.removeMarker = function(markerId) {
|
||||
ace.VirtualRenderer.prototype.removeMarker = function(markerId) {
|
||||
this.markerLayer.removeMarker(markerId);
|
||||
};
|
||||
|
||||
VirtualRenderer.prototype.updateCursor = function(position)
|
||||
ace.VirtualRenderer.prototype.updateCursor = function(position)
|
||||
{
|
||||
this.cursorLayer.setCursor(position);
|
||||
this.cursorLayer.update(this.layerConfig);
|
||||
};
|
||||
|
||||
VirtualRenderer.prototype.hideCursor = function() {
|
||||
ace.VirtualRenderer.prototype.hideCursor = function() {
|
||||
this.cursorLayer.hideCursor();
|
||||
};
|
||||
|
||||
VirtualRenderer.prototype.showCursor = function() {
|
||||
ace.VirtualRenderer.prototype.showCursor = function() {
|
||||
this.cursorLayer.showCursor();
|
||||
};
|
||||
|
||||
VirtualRenderer.prototype.scrollCursorIntoView = function()
|
||||
ace.VirtualRenderer.prototype.scrollCursorIntoView = function()
|
||||
{
|
||||
var pos = this.cursorLayer.getPixelPosition();
|
||||
|
||||
|
|
@ -161,15 +163,15 @@ VirtualRenderer.prototype.scrollCursorIntoView = function()
|
|||
}
|
||||
},
|
||||
|
||||
VirtualRenderer.prototype.getScrollTop = function() {
|
||||
ace.VirtualRenderer.prototype.getScrollTop = function() {
|
||||
return this.scrollTop;
|
||||
};
|
||||
|
||||
VirtualRenderer.prototype.scrollToRow = function(row) {
|
||||
ace.VirtualRenderer.prototype.scrollToRow = function(row) {
|
||||
this.scrollToY(row*this.lineHeight);
|
||||
}
|
||||
|
||||
VirtualRenderer.prototype.scrollToY = function(scrollTop)
|
||||
ace.VirtualRenderer.prototype.scrollToY = function(scrollTop)
|
||||
{
|
||||
var maxHeight = this.lines.length * this.lineHeight - this.scroller.clientHeight;
|
||||
var scrollTop = Math.max(0, Math.min(maxHeight, scrollTop));
|
||||
|
|
@ -180,7 +182,7 @@ VirtualRenderer.prototype.scrollToY = function(scrollTop)
|
|||
}
|
||||
};
|
||||
|
||||
VirtualRenderer.prototype.screenToTextCoordinates = function(pageX, pageY)
|
||||
ace.VirtualRenderer.prototype.screenToTextCoordinates = function(pageX, pageY)
|
||||
{
|
||||
var canvasPos = this.scroller.getBoundingClientRect();
|
||||
|
||||
|
|
@ -193,19 +195,19 @@ VirtualRenderer.prototype.screenToTextCoordinates = function(pageX, pageY)
|
|||
}
|
||||
};
|
||||
|
||||
VirtualRenderer.prototype.visualizeFocus = function() {
|
||||
ace.VirtualRenderer.prototype.visualizeFocus = function() {
|
||||
this.container.className = "editor focus";
|
||||
};
|
||||
|
||||
VirtualRenderer.prototype.visualizeBlur = function() {
|
||||
ace.VirtualRenderer.prototype.visualizeBlur = function() {
|
||||
this.container.className = "editor";
|
||||
};
|
||||
|
||||
VirtualRenderer.prototype.showComposition = function(position) {
|
||||
ace.VirtualRenderer.prototype.showComposition = function(position) {
|
||||
};
|
||||
|
||||
VirtualRenderer.prototype.setCompositionText = function(text) {
|
||||
ace.VirtualRenderer.prototype.setCompositionText = function(text) {
|
||||
};
|
||||
|
||||
VirtualRenderer.prototype.hideComposition = function() {
|
||||
ace.VirtualRenderer.prototype.hideComposition = function() {
|
||||
};
|
||||
|
|
@ -1,11 +1,13 @@
|
|||
if (!window.ace) ace = {};
|
||||
|
||||
(function() {
|
||||
|
||||
window.XML = {};
|
||||
ace.XML = {};
|
||||
|
||||
// regexp must not have capturing parentheses
|
||||
// regexps are ordered -> the first match is used
|
||||
|
||||
XML.RULES = {
|
||||
ace.XML.RULES = {
|
||||
start :
|
||||
[
|
||||
{
|
||||
|
|
|
|||
62
src/lib.js
62
src/lib.js
|
|
@ -1,8 +1,8 @@
|
|||
if (!window.ace) ace = {};
|
||||
|
||||
(function() {
|
||||
|
||||
window.lib = {};
|
||||
|
||||
lib.addListener = function(elem, type, callback) {
|
||||
ace.addListener = function(elem, type, callback) {
|
||||
if (elem.addEventListener) {
|
||||
return elem.addEventListener(type, callback, false);
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@ lib.addListener = function(elem, type, callback) {
|
|||
}
|
||||
}
|
||||
|
||||
lib.removeListener = function(elem, type, callback) {
|
||||
ace.removeListener = function(elem, type, callback) {
|
||||
if (elem.removeEventListener) {
|
||||
return elem.removeEventListener(type, callback, false);
|
||||
}
|
||||
|
|
@ -24,7 +24,7 @@ lib.removeListener = function(elem, type, callback) {
|
|||
}
|
||||
}
|
||||
|
||||
lib.setText = function(elem, text) {
|
||||
ace.setText = function(elem, text) {
|
||||
if (elem.innerText !== undefined) {
|
||||
elem.innerText = text;
|
||||
}
|
||||
|
|
@ -33,20 +33,20 @@ lib.setText = function(elem, text) {
|
|||
}
|
||||
}
|
||||
|
||||
lib.stopEvent = function(e) {
|
||||
lib.stopPropagation(e);
|
||||
lib.preventDefault(e);
|
||||
ace.stopEvent = function(e) {
|
||||
ace.stopPropagation(e);
|
||||
ace.preventDefault(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
lib.stopPropagation = function(e) {
|
||||
ace.stopPropagation = function(e) {
|
||||
if (e.stopPropagation)
|
||||
e.stopPropagation();
|
||||
else
|
||||
e.cancelBubble = true;
|
||||
}
|
||||
|
||||
lib.preventDefault = function(e)
|
||||
ace.preventDefault = function(e)
|
||||
{
|
||||
if (e.preventDefault)
|
||||
e.preventDefault();
|
||||
|
|
@ -54,7 +54,7 @@ lib.preventDefault = function(e)
|
|||
e.returnValue = false;
|
||||
}
|
||||
|
||||
lib.inherits = function(ctor, superCtor) {
|
||||
ace.inherits = function(ctor, superCtor) {
|
||||
var tempCtor = function(){};
|
||||
tempCtor.prototype = superCtor.prototype;
|
||||
ctor.super_ = superCtor.prototype;
|
||||
|
|
@ -62,25 +62,25 @@ lib.inherits = function(ctor, superCtor) {
|
|||
ctor.prototype.constructor = ctor;
|
||||
};
|
||||
|
||||
lib.getInnerWidth = function(element)
|
||||
ace.getInnerWidth = function(element)
|
||||
{
|
||||
return (
|
||||
parseInt(lib.computedStyle(element, "paddingLeft")) +
|
||||
parseInt(lib.computedStyle(element, "paddingRight")) +
|
||||
parseInt(ace.computedStyle(element, "paddingLeft")) +
|
||||
parseInt(ace.computedStyle(element, "paddingRight")) +
|
||||
element.clientWidth
|
||||
);
|
||||
};
|
||||
|
||||
lib.getInnerHeight = function(element)
|
||||
ace.getInnerHeight = function(element)
|
||||
{
|
||||
return (
|
||||
parseInt(lib.computedStyle(element, "paddingTop")) +
|
||||
parseInt(lib.computedStyle(element, "paddingBottom")) +
|
||||
parseInt(ace.computedStyle(element, "paddingTop")) +
|
||||
parseInt(ace.computedStyle(element, "paddingBottom")) +
|
||||
element.clientHeight
|
||||
);
|
||||
};
|
||||
|
||||
lib.computedStyle = function(element, style)
|
||||
ace.computedStyle = function(element, style)
|
||||
{
|
||||
if (window.getComputedStyle) {
|
||||
return (window.getComputedStyle(element, null))[style];
|
||||
|
|
@ -89,7 +89,7 @@ lib.computedStyle = function(element, style)
|
|||
}
|
||||
}
|
||||
|
||||
lib.scrollbarHeight = function() {
|
||||
ace.scrollbarHeight = function() {
|
||||
var el = document.createElement("div");
|
||||
var style = el.style;
|
||||
|
||||
|
|
@ -105,13 +105,13 @@ lib.scrollbarHeight = function() {
|
|||
return height;
|
||||
}
|
||||
|
||||
lib.bind = function(fcn, context) {
|
||||
ace.bind = function(fcn, context) {
|
||||
return function() {
|
||||
return fcn.apply(context, arguments);
|
||||
}
|
||||
}
|
||||
|
||||
lib.capture = function(el, eventHandler, releaseCaptureHandler)
|
||||
ace.capture = function(el, eventHandler, releaseCaptureHandler)
|
||||
{
|
||||
function onMouseMove(e)
|
||||
{
|
||||
|
|
@ -134,17 +134,17 @@ lib.capture = function(el, eventHandler, releaseCaptureHandler)
|
|||
document.addEventListener("mouseup", onMouseUp, true);
|
||||
}
|
||||
|
||||
lib.addMouseWheelListener = function(el, callback)
|
||||
ace.addMouseWheelListener = function(el, callback)
|
||||
{
|
||||
var listener = function(e) {
|
||||
e.wheel = (e.wheelDelta) ? e.wheelDelta / 120 : -(e.detail || 0) / 3;
|
||||
callback(e);
|
||||
}
|
||||
lib.addListener(el, "DOMMouseScroll", listener);
|
||||
lib.addListener(el, "mousewheel", listener);
|
||||
ace.addListener(el, "DOMMouseScroll", listener);
|
||||
ace.addListener(el, "mousewheel", listener);
|
||||
};
|
||||
|
||||
lib.autoremoveListener = function(el, type, callback, timeout)
|
||||
ace.autoremoveListener = function(el, type, callback, timeout)
|
||||
{
|
||||
var listener = function(e)
|
||||
{
|
||||
|
|
@ -154,18 +154,18 @@ lib.autoremoveListener = function(el, type, callback, timeout)
|
|||
}
|
||||
|
||||
var remove = function() {
|
||||
lib.removeListener(el, type, listener);
|
||||
ace.removeListener(el, type, listener);
|
||||
};
|
||||
|
||||
lib.addListener(el, type, listener);
|
||||
ace.addListener(el, type, listener);
|
||||
var timeoutId = setTimeout(remove, timeout);
|
||||
}
|
||||
|
||||
lib.addTripleClickListener = function(el, callback)
|
||||
ace.addTripleClickListener = function(el, callback)
|
||||
{
|
||||
lib.addListener(el, "mousedown", function() {
|
||||
lib.autoremoveListener(el, "mousedown", function() {
|
||||
lib.autoremoveListener(el, "mousedown", callback, 300);
|
||||
ace.addListener(el, "mousedown", function() {
|
||||
ace.autoremoveListener(el, "mousedown", function() {
|
||||
ace.autoremoveListener(el, "mousedown", callback, 300);
|
||||
}, 300);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue