From f9fa5f0e664f26b72fe706cd67b5a6ab97f8186b Mon Sep 17 00:00:00 2001 From: Eddy Bruel Date: Thu, 21 Oct 2010 18:52:07 +0200 Subject: [PATCH] Fixed a bug in syntax highlighting. --- src/ace/Editor.js | 49 +++++++---- src/ace/Tokenizer.js | 10 +-- src/ace/mode/XmlHighlightRules.js | 134 +++++++++++------------------- 3 files changed, 84 insertions(+), 109 deletions(-) diff --git a/src/ace/Editor.js b/src/ace/Editor.js index a3247e4b..7ff1184b 100644 --- a/src/ace/Editor.js +++ b/src/ace/Editor.js @@ -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) { diff --git a/src/ace/Tokenizer.js b/src/ace/Tokenizer.js index 71b5d54f..4be24df4 100644 --- a/src/ace/Tokenizer.js +++ b/src/ace/Tokenizer.js @@ -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, diff --git a/src/ace/mode/XmlHighlightRules.js b/src/ace/mode/XmlHighlightRules.js index e0670ee7..e3274867 100644 --- a/src/ace/mode/XmlHighlightRules.js +++ b/src/ace/mode/XmlHighlightRules.js @@ -1,87 +1,47 @@ -/** - * Ajax.org Code Editor (ACE) - * - * @copyright 2010, Ajax.org Services B.V. - * @license LGPLv3 - * @author Fabian Jakobs - */ -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; -}); \ No newline at end of file + + + + + + + + + + + + + Open files at startup + + + + + + + + + OK + Cancel + Apply + + + + \ No newline at end of file