Fixed a bug in syntax highlighting.

This commit is contained in:
Eddy Bruel 2010-10-21 18:52:07 +02:00
commit f9fa5f0e66
3 changed files with 84 additions and 109 deletions

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,23 +542,25 @@ 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) {

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

@ -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>