Merge branch 'master' of github.com:ajaxorg/editor
This commit is contained in:
commit
f704987a14
7 changed files with 134 additions and 165 deletions
|
|
@ -193,7 +193,7 @@ function getDoc() {
|
||||||
|
|
||||||
var modeEl = document.getElementById("mode");
|
var modeEl = document.getElementById("mode");
|
||||||
modeEl.onchange = function() {
|
modeEl.onchange = function() {
|
||||||
editor.getDocument().setTheme(modeEl.value);
|
editor.getDocument().setMode(modes[modeEl.value] || modes.text);
|
||||||
};
|
};
|
||||||
|
|
||||||
var modes = {
|
var modes = {
|
||||||
|
|
|
||||||
|
|
@ -76,11 +76,14 @@ var Document = function(text, mode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (undoManager) {
|
if (undoManager) {
|
||||||
undoManager.setDocument(this);
|
//undoManager.setDocument(this);
|
||||||
var self = this;
|
var self = this;
|
||||||
this.$informUndoManager = lang.deferredCall(function() {
|
this.$informUndoManager = lang.deferredCall(function() {
|
||||||
if (self.$deltas.length > 0)
|
if (self.$deltas.length > 0)
|
||||||
undoManager.notify(self.$deltas);
|
undoManager.execute({
|
||||||
|
action : "aceupdate",
|
||||||
|
args : [self.$deltas, self]
|
||||||
|
});
|
||||||
self.$deltas = [];
|
self.$deltas = [];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -249,21 +252,10 @@ var Document = function(text, mode) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a verbatim copy of the given line as it is in the document
|
|
||||||
*/
|
|
||||||
this.getLine = function(row) {
|
this.getLine = function(row) {
|
||||||
return this.lines[row] || "";
|
return this.lines[row] || "";
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a line as it is displayed on screen. Tabs are replaced by spaces.
|
|
||||||
*/
|
|
||||||
this.getDisplayLine = function(row) {
|
|
||||||
var tab = new Array(this.getTabSize()+1).join(" ");
|
|
||||||
return this.lines[row].replace(/\t/g, tab);
|
|
||||||
};
|
|
||||||
|
|
||||||
this.getLines = function(firstRow, lastRow) {
|
this.getLines = function(firstRow, lastRow) {
|
||||||
return this.lines.slice(firstRow, lastRow+1);
|
return this.lines.slice(firstRow, lastRow+1);
|
||||||
};
|
};
|
||||||
|
|
@ -564,27 +556,34 @@ var Document = function(text, mode) {
|
||||||
return indentString.length;
|
return indentString.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.outdentRows = function(range, indentString) {
|
this.outdentRows = function (range) {
|
||||||
outdentLength = indentString.length;
|
var deleteRange = new Range(0, 0, 0, 0),
|
||||||
|
size = this.getTabSize();
|
||||||
|
|
||||||
for (var i=range.start.row; i<= range.end.row; i++) {
|
for (var i = range.start.row; i <= range.end.row; ++i) {
|
||||||
if (this.getLine(i).substr(0, outdentLength) !== indentString) {
|
var line = this.getLine(i);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var deleteRange = new Range(0, 0, 0, outdentLength);
|
|
||||||
|
|
||||||
for (var i=range.start.row; i<= range.end.row; i++)
|
|
||||||
{
|
|
||||||
deleteRange.start.row = i;
|
deleteRange.start.row = i;
|
||||||
deleteRange.end.row = i;
|
deleteRange.end.row = i;
|
||||||
|
for (var j = 0; j < size; ++j)
|
||||||
|
if (line.charAt(j) != ' ')
|
||||||
|
break;
|
||||||
|
if (j < size && line.charAt(j) == '\t') {
|
||||||
|
deleteRange.start.column = j;
|
||||||
|
deleteRange.end.column = j + 1;
|
||||||
|
} else {
|
||||||
|
deleteRange.start.column = 0;
|
||||||
|
deleteRange.end.column = j;
|
||||||
|
}
|
||||||
|
if (i == range.start.row)
|
||||||
|
range.start.column -= deleteRange.end.column - deleteRange.start.column;
|
||||||
|
if (i == range.end.row)
|
||||||
|
range.end.column -= deleteRange.end.column - deleteRange.start.column;
|
||||||
this.$remove(deleteRange);
|
this.$remove(deleteRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.fireChangeEvent(range.start.row, range.end.row);
|
this.fireChangeEvent(range.start.row, range.end.row);
|
||||||
return -outdentLength;
|
return range;
|
||||||
};
|
}
|
||||||
|
|
||||||
this.moveLinesUp = function(firstRow, lastRow) {
|
this.moveLinesUp = function(firstRow, lastRow) {
|
||||||
if (firstRow <= 0) return 0;
|
if (firstRow <= 0) return 0;
|
||||||
|
|
|
||||||
|
|
@ -345,7 +345,9 @@ var Editor = function(renderer, doc) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.onMouseWheel = function(e) {
|
this.onMouseWheel = function(e) {
|
||||||
this.renderer.scrollBy(e.wheelX * 2, e.wheelY * 2);
|
var speed = this.$scrollSpeed * 2;
|
||||||
|
|
||||||
|
this.renderer.scrollBy(e.wheelX * speed, e.wheelY * speed);
|
||||||
return event.preventDefault(e);
|
return event.preventDefault(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -442,6 +444,16 @@ var Editor = function(renderer, doc) {
|
||||||
this.setOverwrite(!this.$overwrite);
|
this.setOverwrite(!this.$overwrite);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
this.$scrollSpeed = 1;
|
||||||
|
this.setScrollSpeed = function(speed) {
|
||||||
|
this.$scrollSpeed = speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.getScrollSpeed = function() {
|
||||||
|
return this.$scrollSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
this.$selectionStyle = "line";
|
this.$selectionStyle = "line";
|
||||||
this.setSelectionStyle = function(style) {
|
this.setSelectionStyle = function(style) {
|
||||||
if (this.$selectionStyle == style) return;
|
if (this.$selectionStyle == style) return;
|
||||||
|
|
@ -451,6 +463,7 @@ var Editor = function(renderer, doc) {
|
||||||
this.$dispatchEvent("changeSelectionStyle", {data: style});
|
this.$dispatchEvent("changeSelectionStyle", {data: style});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
this.getSelectionStyle = function() {
|
this.getSelectionStyle = function() {
|
||||||
return this.$selectionStyle;
|
return this.$selectionStyle;
|
||||||
};
|
};
|
||||||
|
|
@ -529,37 +542,35 @@ var Editor = function(renderer, doc) {
|
||||||
if (this.$readOnly)
|
if (this.$readOnly)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (this.selection.isMultiLine()) {
|
var range = this.getSelectionRange();
|
||||||
var addedColumns = this.doc.indentRows(this.getSelectionRange(), "\t");
|
|
||||||
this.selection.shiftSelection(addedColumns);
|
if (range.start.row < range.end.row ||
|
||||||
|
range.start.column < range.end.column) {
|
||||||
|
var count = this.doc.indentRows(this.getSelectionRange(), "\t");
|
||||||
|
|
||||||
|
this.selection.shiftSelection(count);
|
||||||
} else {
|
} else {
|
||||||
if (!this.doc.getUseSoftTabs())
|
var indentString;
|
||||||
return this.onTextInput("\t");
|
|
||||||
|
|
||||||
var cursor = this.doc.remove(this.getSelectionRange());
|
if (this.doc.getUseSoftTabs()) {
|
||||||
this.clearSelection();
|
var size = this.doc.getTabSize(),
|
||||||
|
count = (size - this.getCursorPosition().column % size);
|
||||||
|
|
||||||
// compute indent string
|
indentString = lang.stringRepeat(" ", count);
|
||||||
var indentString = lang.stringRepeat(" ", this.doc.getTabSize() - (cursor.column % this.doc.getTabSize()));
|
} else
|
||||||
var addedColumns = this.doc.indentRows(this.getSelectionRange(), indentString);
|
indentString = "\t";
|
||||||
cursor.column += addedColumns;
|
return this.onTextInput(indentString);
|
||||||
this.moveCursorToPosition(cursor);
|
|
||||||
}
|
}
|
||||||
this.$updateDesiredColumn();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.blockOutdent = function(indentString) {
|
this.blockOutdent = function(indentString) {
|
||||||
if (this.$readOnly)
|
if (this.$readOnly)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var indentString = indentString || this.doc.getTabString();
|
var selection = this.doc.getSelection(),
|
||||||
var addedColumns = this.doc.outdentRows(this.getSelectionRange(), indentString);
|
range = this.doc.outdentRows(selection.getRange());
|
||||||
|
|
||||||
// besides the indent string also outdent tabs
|
selection.setSelectionRange(range, selection.isBackwards());
|
||||||
if (addedColumns == 0 && indentString != "\t")
|
|
||||||
var addedColumns = this.doc.outdentRows(this.getSelectionRange(), "\t");
|
|
||||||
|
|
||||||
this.selection.shiftSelection(addedColumns);
|
|
||||||
this.$updateDesiredColumn();
|
this.$updateDesiredColumn();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ var Selection = function(doc) {
|
||||||
var anchor = this.getSelectionAnchor();
|
var anchor = this.getSelectionAnchor();
|
||||||
var lead = this.getSelectionLead();
|
var lead = this.getSelectionLead();
|
||||||
|
|
||||||
var isBackwards = this.$isBackwards();
|
var isBackwards = this.isBackwards();
|
||||||
|
|
||||||
if (!isBackwards || anchor.column !== 0)
|
if (!isBackwards || anchor.column !== 0)
|
||||||
this.setSelectionAnchor(anchor.row, anchor.column + columns);
|
this.setSelectionAnchor(anchor.row, anchor.column + columns);
|
||||||
|
|
@ -91,7 +91,7 @@ var Selection = function(doc) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$isBackwards = function() {
|
this.isBackwards = function() {
|
||||||
var anchor = this.selectionAnchor || this.selectionLead;
|
var anchor = this.selectionAnchor || this.selectionLead;
|
||||||
var lead = this.selectionLead;
|
var lead = this.selectionLead;
|
||||||
return (anchor.row > lead.row || (anchor.row == lead.row && anchor.column > lead.column));
|
return (anchor.row > lead.row || (anchor.row == lead.row && anchor.column > lead.column));
|
||||||
|
|
@ -101,7 +101,7 @@ var Selection = function(doc) {
|
||||||
var anchor = this.selectionAnchor || this.selectionLead;
|
var anchor = this.selectionAnchor || this.selectionLead;
|
||||||
var lead = this.selectionLead;
|
var lead = this.selectionLead;
|
||||||
|
|
||||||
if (this.$isBackwards()) {
|
if (this.isBackwards()) {
|
||||||
return Range.fromPoints(lead, anchor);
|
return Range.fromPoints(lead, anchor);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -116,7 +116,6 @@ var Selection = function(doc) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
this.selectAll = function() {
|
this.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);
|
||||||
|
|
@ -126,9 +125,14 @@ var Selection = function(doc) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.setSelectionRange = function(range) {
|
this.setSelectionRange = function(range, reverse) {
|
||||||
this.setSelectionAnchor(range.start.row, range.start.column);
|
if (reverse) {
|
||||||
this.selectTo(range.end.row, range.end.column);
|
this.setSelectionAnchor(range.end.row, range.end.column);
|
||||||
|
this.selectTo(range.start.row, range.start.column);
|
||||||
|
} else {
|
||||||
|
this.setSelectionAnchor(range.start.row, range.start.column);
|
||||||
|
this.selectTo(range.end.row, range.end.column);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$moveSelection = function(mover) {
|
this.$moveSelection = function(mover) {
|
||||||
|
|
@ -281,14 +285,7 @@ var Selection = function(doc) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.moveCursorLineStart = function() {
|
this.moveCursorLineStart = function() {
|
||||||
var row = this.selectionLead.row;
|
this.moveCursorTo(this.selectionLead.row, 0);
|
||||||
var column = this.selectionLead.column;
|
|
||||||
var beforeCursor = this.doc.getDisplayLine(row).slice(0, column);
|
|
||||||
var leadingSpace = beforeCursor.match(/^\s+/);
|
|
||||||
if (!leadingSpace || leadingSpace[0].length >= column)
|
|
||||||
this.moveCursorTo(this.selectionLead.row, 0);
|
|
||||||
else
|
|
||||||
this.moveCursorTo(this.selectionLead.row, leadingSpace[0].length);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.moveCursorLineEnd = function() {
|
this.moveCursorLineEnd = function() {
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,7 @@ var Tokenizer = function(rules) {
|
||||||
ruleRegExps.push(state[i].regex);
|
ruleRegExps.push(state[i].regex);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.regExps[key] = new RegExp("(?:(" + ruleRegExps.join(")|(")
|
this.regExps[key] = new RegExp("(?:(" + ruleRegExps.join(")|(") + ")|(.))", "g");
|
||||||
+ ")|(.))", "g");
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -48,7 +47,7 @@ var Tokenizer = function(rules) {
|
||||||
if (re.lastIndex == lastIndex) { throw new Error("tokenizer error"); }
|
if (re.lastIndex == lastIndex) { throw new Error("tokenizer error"); }
|
||||||
lastIndex = re.lastIndex;
|
lastIndex = re.lastIndex;
|
||||||
|
|
||||||
window.LOG && jstestdriver.console.log(currentState, match);
|
window.LOG && console.log(currentState, 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]) {
|
||||||
|
|
@ -71,6 +70,7 @@ var Tokenizer = function(rules) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
if (token.type !== type) {
|
if (token.type !== type) {
|
||||||
if (token.type) {
|
if (token.type) {
|
||||||
tokens.push(token);
|
tokens.push(token);
|
||||||
|
|
@ -88,7 +88,7 @@ var Tokenizer = function(rules) {
|
||||||
tokens.push(token);
|
tokens.push(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.LOG && jstestdriver.console.log(tokens, currentState);
|
window.LOG && console.log(tokens, currentState);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
tokens : tokens,
|
tokens : tokens,
|
||||||
|
|
|
||||||
|
|
@ -14,12 +14,14 @@ var UndoManager = function() {
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
this.$doc = null;
|
/*this.$doc = null;
|
||||||
this.setDocument = function(doc) {
|
this.setDocument = function(doc) {
|
||||||
this.$doc = doc;
|
this.$doc = doc;
|
||||||
};
|
};*/
|
||||||
|
|
||||||
this.notify = function(deltas) {
|
this.execute = function(options) {
|
||||||
|
var deltas = options.args[0];
|
||||||
|
this.$doc = options.args[1];
|
||||||
this.$undoStack.push(deltas);
|
this.$undoStack.push(deltas);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,87 +1,47 @@
|
||||||
/**
|
<a:application xmlns:a="http://ajax.org/2005/aml">
|
||||||
* Ajax.org Code Editor (ACE)
|
<a:window
|
||||||
*
|
id = "winSettings"
|
||||||
* @copyright 2010, Ajax.org Services B.V.
|
title = "Settings"
|
||||||
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
icon = ""
|
||||||
* @author Fabian Jakobs <fabian AT ajax DOT org>
|
center = "true"
|
||||||
*/
|
buttons = "close"
|
||||||
require.def("ace/mode/XmlHighlightRules",
|
kbclose = "true"
|
||||||
[
|
width = "550"
|
||||||
"ace/lib/oop",
|
height = "300">
|
||||||
"ace/mode/TextHighlightRules"
|
<a:vbox anchors="0 0 0 0">
|
||||||
], function(oop, TextHighlightRules) {
|
<a:hbox padding="8" edge="10" model="{require('ext/settings/settings').model}" actiontracker="atSettings" flex="1">
|
||||||
|
<a:vbox width="150" padding="5">
|
||||||
var XmlHighlightRules = function() {
|
<a:textbox initial-message="Filter" />
|
||||||
|
<a:tree flex="1"
|
||||||
// regexp must not have capturing parentheses
|
each = "[node()[local-name() and not(local-name() = 'auto')]]"
|
||||||
// regexps are ordered -> the first match is used
|
eachvalue = "[@page]"
|
||||||
|
caption = "[@name]"
|
||||||
this.$rules = {
|
icon = "{[@icon] || 'folder.png'}"
|
||||||
start : [ {
|
startcollapsed = "false"
|
||||||
token : "text",
|
onafterselect = "
|
||||||
regex : "<\\!\\[CDATA\\[",
|
var page = pgSettings.getPage(this.value);
|
||||||
next : "cdata"
|
if (!page) return;
|
||||||
}, {
|
page.setAttribute('model', this.selected);
|
||||||
token : "xml_pe",
|
pgSettings.set(this.value);
|
||||||
regex : "<\\?.*?\\?>"
|
"/>
|
||||||
}, {
|
</a:vbox>
|
||||||
token : "comment",
|
<a:splitter />
|
||||||
regex : "<\\!--",
|
<a:pages id="pgSettings" flex="1">
|
||||||
next : "comment"
|
<a:page id="pgSettingsGeneral" render="runtime">
|
||||||
}, {
|
<a:frame caption="General" anchors="0 0 0 0">
|
||||||
token : "text", // opening tag
|
<a:checkbox value="[@openfiles]">Open files at startup</a:checkbox>
|
||||||
regex : "<\\/?",
|
</a:frame>
|
||||||
next : "tag"
|
</a:page>
|
||||||
}, {
|
<a:page id="pgSettingsEditor" render="runtime">
|
||||||
token : "text",
|
<a:frame caption="Editor" anchors="0 0 0 0"></a:frame>
|
||||||
regex : "\\s+"
|
</a:page>
|
||||||
}, {
|
</a:pages>
|
||||||
token : "text",
|
</a:hbox>
|
||||||
regex : "[^<]+"
|
<a:hbox pack="end" edge="0 10 5 10" padding="5">
|
||||||
} ],
|
<a:button width="80" default="2" class="ui-btn-green">OK</a:button>
|
||||||
|
<a:button width="80" onclick="winSettings.hide();">Cancel</a:button>
|
||||||
tag : [ {
|
<a:button width="80" disabled="{!atSettings.undolength}">Apply</a:button>
|
||||||
token : "text",
|
</a:hbox>
|
||||||
regex : ">",
|
</a:vbox>
|
||||||
next : "start"
|
</a:window>
|
||||||
}, {
|
</a:application>
|
||||||
token : "keyword",
|
|
||||||
regex : "[-_a-zA-Z0-9:]+"
|
|
||||||
}, {
|
|
||||||
token : "text",
|
|
||||||
regex : "\\s+"
|
|
||||||
}, {
|
|
||||||
token : "string",
|
|
||||||
regex : '".*?"'
|
|
||||||
}, {
|
|
||||||
token : "string",
|
|
||||||
regex : "'.*?'"
|
|
||||||
} ],
|
|
||||||
|
|
||||||
cdata : [ {
|
|
||||||
token : "text",
|
|
||||||
regex : "\\]\\]>",
|
|
||||||
next : "start"
|
|
||||||
}, {
|
|
||||||
token : "text",
|
|
||||||
regex : "\\s+"
|
|
||||||
}, {
|
|
||||||
token : "text",
|
|
||||||
regex : ".+"
|
|
||||||
} ],
|
|
||||||
|
|
||||||
comment : [ {
|
|
||||||
token : "comment",
|
|
||||||
regex : ".*?-->",
|
|
||||||
next : "start"
|
|
||||||
}, {
|
|
||||||
token : "comment",
|
|
||||||
regex : ".+"
|
|
||||||
} ]
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
oop.inherits(XmlHighlightRules, TextHighlightRules);
|
|
||||||
|
|
||||||
return XmlHighlightRules;
|
|
||||||
});
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue