Merge branch 'master' of github.com:ajaxorg/editor

This commit is contained in:
Fabian Jakobs 2010-10-22 11:39:24 +02:00
commit f704987a14
7 changed files with 134 additions and 165 deletions

View file

@ -193,7 +193,7 @@ function getDoc() {
var modeEl = document.getElementById("mode");
modeEl.onchange = function() {
editor.getDocument().setTheme(modeEl.value);
editor.getDocument().setMode(modes[modeEl.value] || modes.text);
};
var modes = {

View file

@ -76,11 +76,14 @@ var Document = function(text, mode) {
}
if (undoManager) {
undoManager.setDocument(this);
//undoManager.setDocument(this);
var self = this;
this.$informUndoManager = lang.deferredCall(function() {
if (self.$deltas.length > 0)
undoManager.notify(self.$deltas);
undoManager.execute({
action : "aceupdate",
args : [self.$deltas, self]
});
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) {
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) {
return this.lines.slice(firstRow, lastRow+1);
};
@ -564,27 +556,34 @@ var Document = function(text, mode) {
return indentString.length;
};
this.outdentRows = function(range, indentString) {
outdentLength = indentString.length;
for (var i=range.start.row; i<= range.end.row; i++) {
if (this.getLine(i).substr(0, outdentLength) !== indentString) {
return 0;
}
}
var deleteRange = new Range(0, 0, 0, outdentLength);
for (var i=range.start.row; i<= range.end.row; i++)
{
this.outdentRows = function (range) {
var deleteRange = new Range(0, 0, 0, 0),
size = this.getTabSize();
for (var i = range.start.row; i <= range.end.row; ++i) {
var line = this.getLine(i);
deleteRange.start.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.fireChangeEvent(range.start.row, range.end.row);
return -outdentLength;
};
return range;
}
this.moveLinesUp = function(firstRow, lastRow) {
if (firstRow <= 0) return 0;

View file

@ -10,7 +10,7 @@ require.def("ace/Editor",
"ace/ace",
"ace/lib/event",
"ace/lib/lang",
"ace/TextInput",
"ace/TextInput",
"ace/KeyBinding",
"ace/Document",
"ace/Search",
@ -345,7 +345,9 @@ var Editor = function(renderer, doc) {
};
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);
};
@ -442,6 +444,16 @@ var Editor = function(renderer, doc) {
this.setOverwrite(!this.$overwrite);
};
this.$scrollSpeed = 1;
this.setScrollSpeed = function(speed) {
this.$scrollSpeed = speed;
}
this.getScrollSpeed = function() {
return this.$scrollSpeed;
}
this.$selectionStyle = "line";
this.setSelectionStyle = function(style) {
if (this.$selectionStyle == style) return;
@ -451,6 +463,7 @@ var Editor = function(renderer, doc) {
this.$dispatchEvent("changeSelectionStyle", {data: style});
};
this.getSelectionStyle = function() {
return this.$selectionStyle;
};
@ -529,37 +542,35 @@ var Editor = function(renderer, doc) {
if (this.$readOnly)
return;
if (this.selection.isMultiLine()) {
var addedColumns = this.doc.indentRows(this.getSelectionRange(), "\t");
this.selection.shiftSelection(addedColumns);
} else {
if (!this.doc.getUseSoftTabs())
return this.onTextInput("\t");
var range = this.getSelectionRange();
var cursor = this.doc.remove(this.getSelectionRange());
this.clearSelection();
// compute indent string
var indentString = lang.stringRepeat(" ", this.doc.getTabSize() - (cursor.column % this.doc.getTabSize()));
var addedColumns = this.doc.indentRows(this.getSelectionRange(), indentString);
cursor.column += addedColumns;
this.moveCursorToPosition(cursor);
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 {
var indentString;
if (this.doc.getUseSoftTabs()) {
var size = this.doc.getTabSize(),
count = (size - this.getCursorPosition().column % size);
indentString = lang.stringRepeat(" ", count);
} else
indentString = "\t";
return this.onTextInput(indentString);
}
this.$updateDesiredColumn();
};
this.blockOutdent = function(indentString) {
if (this.$readOnly)
return;
var indentString = indentString || this.doc.getTabString();
var addedColumns = this.doc.outdentRows(this.getSelectionRange(), indentString);
// besides the indent string also outdent tabs
if (addedColumns == 0 && indentString != "\t")
var addedColumns = this.doc.outdentRows(this.getSelectionRange(), "\t");
this.selection.shiftSelection(addedColumns);
var selection = this.doc.getSelection(),
range = this.doc.outdentRows(selection.getRange());
selection.setSelectionRange(range, selection.isBackwards());
this.$updateDesiredColumn();
};

View file

@ -79,7 +79,7 @@ var Selection = function(doc) {
var anchor = this.getSelectionAnchor();
var lead = this.getSelectionLead();
var isBackwards = this.$isBackwards();
var isBackwards = this.isBackwards();
if (!isBackwards || anchor.column !== 0)
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 lead = this.selectionLead;
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 lead = this.selectionLead;
if (this.$isBackwards()) {
if (this.isBackwards()) {
return Range.fromPoints(lead, anchor);
}
else {
@ -116,7 +116,6 @@ var Selection = function(doc) {
}
};
this.selectAll = function() {
var lastRow = this.doc.getLength() - 1;
this.setSelectionAnchor(lastRow, this.doc.getLine(lastRow).length);
@ -126,9 +125,14 @@ var Selection = function(doc) {
});
};
this.setSelectionRange = function(range) {
this.setSelectionAnchor(range.start.row, range.start.column);
this.selectTo(range.end.row, range.end.column);
this.setSelectionRange = function(range, reverse) {
if (reverse) {
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) {
@ -281,14 +285,7 @@ var Selection = function(doc) {
};
this.moveCursorLineStart = function() {
var row = this.selectionLead.row;
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.moveCursorTo(this.selectionLead.row, 0);
};
this.moveCursorLineEnd = function() {

View file

@ -19,8 +19,7 @@ var Tokenizer = function(rules) {
ruleRegExps.push(state[i].regex);
};
this.regExps[key] = new RegExp("(?:(" + ruleRegExps.join(")|(")
+ ")|(.))", "g");
this.regExps[key] = new RegExp("(?:(" + ruleRegExps.join(")|(") + ")|(.))", "g");
}
};
@ -48,7 +47,7 @@ var Tokenizer = function(rules) {
if (re.lastIndex == lastIndex) { throw new Error("tokenizer error"); }
lastIndex = re.lastIndex;
window.LOG && jstestdriver.console.log(currentState, match);
window.LOG && console.log(currentState, match);
for ( var i = 0; i < state.length; i++) {
if (match[i + 1]) {
@ -70,7 +69,8 @@ var Tokenizer = function(rules) {
break;
}
};
if (token.type !== type) {
if (token.type) {
tokens.push(token);
@ -88,7 +88,7 @@ var Tokenizer = function(rules) {
tokens.push(token);
}
window.LOG && jstestdriver.console.log(tokens, currentState);
window.LOG && console.log(tokens, currentState);
return {
tokens : tokens,

View file

@ -14,12 +14,14 @@ var UndoManager = function() {
(function() {
this.$doc = null;
/*this.$doc = null;
this.setDocument = function(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);
};

View file

@ -1,87 +1,47 @@
/**
* Ajax.org Code Editor (ACE)
*
* @copyright 2010, Ajax.org Services B.V.
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
* @author Fabian Jakobs <fabian AT ajax DOT org>
*/
require.def("ace/mode/XmlHighlightRules",
[
"ace/lib/oop",
"ace/mode/TextHighlightRules"
], function(oop, TextHighlightRules) {
var XmlHighlightRules = function() {
// regexp must not have capturing parentheses
// regexps are ordered -> the first match is used
this.$rules = {
start : [ {
token : "text",
regex : "<\\!\\[CDATA\\[",
next : "cdata"
}, {
token : "xml_pe",
regex : "<\\?.*?\\?>"
}, {
token : "comment",
regex : "<\\!--",
next : "comment"
}, {
token : "text", // opening tag
regex : "<\\/?",
next : "tag"
}, {
token : "text",
regex : "\\s+"
}, {
token : "text",
regex : "[^<]+"
} ],
tag : [ {
token : "text",
regex : ">",
next : "start"
}, {
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;
});
<a:application xmlns:a="http://ajax.org/2005/aml">
<a:window
id = "winSettings"
title = "Settings"
icon = ""
center = "true"
buttons = "close"
kbclose = "true"
width = "550"
height = "300">
<a:vbox anchors="0 0 0 0">
<a:hbox padding="8" edge="10" model="{require('ext/settings/settings').model}" actiontracker="atSettings" flex="1">
<a:vbox width="150" padding="5">
<a:textbox initial-message="Filter" />
<a:tree flex="1"
each = "[node()[local-name() and not(local-name() = 'auto')]]"
eachvalue = "[@page]"
caption = "[@name]"
icon = "{[@icon] || 'folder.png'}"
startcollapsed = "false"
onafterselect = "
var page = pgSettings.getPage(this.value);
if (!page) return;
page.setAttribute('model', this.selected);
pgSettings.set(this.value);
"/>
</a:vbox>
<a:splitter />
<a:pages id="pgSettings" flex="1">
<a:page id="pgSettingsGeneral" render="runtime">
<a:frame caption="General" anchors="0 0 0 0">
<a:checkbox value="[@openfiles]">Open files at startup</a:checkbox>
</a:frame>
</a:page>
<a:page id="pgSettingsEditor" render="runtime">
<a:frame caption="Editor" anchors="0 0 0 0"></a:frame>
</a:page>
</a:pages>
</a:hbox>
<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>
<a:button width="80" disabled="{!atSettings.undolength}">Apply</a:button>
</a:hbox>
</a:vbox>
</a:window>
</a:application>