Fixed a bug in syntax highlighting.
This commit is contained in:
parent
e5fbc1f207
commit
f9fa5f0e66
3 changed files with 84 additions and 109 deletions
|
|
@ -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,23 +542,25 @@ 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) {
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
|
||||||
|
|
@ -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