From 858f92d593fdfdd3ea7cd489c7a4ed0b58833f67 Mon Sep 17 00:00:00 2001 From: Eddy Bruel Date: Mon, 25 Oct 2010 18:14:46 +0200 Subject: [PATCH] Added highlighting rule for regular expression Fixed auto-outdenting when typing } --- src/ace/Editor.js | 13 ++++++++++--- src/ace/mode/JavaScriptHighlightRules.js | 3 +++ src/ace/mode/XmlHighlightRules.js | 4 +++- src/ace/theme/tm.css | 4 ++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/ace/Editor.js b/src/ace/Editor.js index 7ff1184b..c4f5e91a 100644 --- a/src/ace/Editor.js +++ b/src/ace/Editor.js @@ -371,6 +371,7 @@ var Editor = function(renderer, doc) { }; this.onTextInput = function(text) { + console.log("onTextInput was called"); if (this.$readOnly) return; @@ -391,20 +392,24 @@ var Editor = function(renderer, doc) { var _self = this; var row = cursor.row; - this.bgTokenizer.getState(cursor.row-1, function(lineState) { + this.bgTokenizer.getState(cursor.row-1, function (lineState) { var shouldOutdent = _self.mode.checkOutdent(lineState, _self.doc.getLine(row), text); var line = _self.doc.getLine(row); var end = _self.doc.insert(cursor, text); - if (line != _self.doc.getLine(row) && text != "\n") { + /* TODO: This shortcut is somehow broken + if (!shouldOutdent && line != _self.doc.getLine(row) && text != "\n") { _self.moveCursorToPosition(end); _self.renderer.scrollCursorIntoView(); return; } - + */ + var line = _self.doc.getLine(row); + console.log("Poofing"); _self.bgTokenizer.getState(row, function(lineState) { // multi line insert + console.log("Poof " + row + "of" + end.row); if (row !== end.row) { var indent = _self.mode.getNextLineIndent(lineState, line, _self.doc.getTabString()); if (indent) { @@ -412,7 +417,9 @@ var Editor = function(renderer, doc) { end.column += _self.doc.indentRows(indentRange, indent); } } else { + console.log("Last row"); if (shouldOutdent) { + console.log("We should outdent"); end.column += _self.mode.autoOutdent(lineState, _self.doc, row); } } diff --git a/src/ace/mode/JavaScriptHighlightRules.js b/src/ace/mode/JavaScriptHighlightRules.js index f3e3659a..3df16162 100644 --- a/src/ace/mode/JavaScriptHighlightRules.js +++ b/src/ace/mode/JavaScriptHighlightRules.js @@ -45,6 +45,9 @@ JavaScriptHighlightRules = function() { token : "comment", // multi line comment regex : "\\/\\*", next : "comment" + }, { + token : "regex", + regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/][gimy]*\\s*(?=[).;]|$)" }, { token : "string", // single line regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]' diff --git a/src/ace/mode/XmlHighlightRules.js b/src/ace/mode/XmlHighlightRules.js index e0670ee7..21a85c36 100644 --- a/src/ace/mode/XmlHighlightRules.js +++ b/src/ace/mode/XmlHighlightRules.js @@ -67,7 +67,7 @@ var XmlHighlightRules = function() { regex : "\\s+" }, { token : "text", - regex : ".+" + regex : "(?:[^\\]]|\\](?!\\]>))+" } ], comment : [ { @@ -81,6 +81,8 @@ var XmlHighlightRules = function() { }; }; +/fd/g + oop.inherits(XmlHighlightRules, TextHighlightRules); return XmlHighlightRules; diff --git a/src/ace/theme/tm.css b/src/ace/theme/tm.css index 0310bcf1..174fee8c 100644 --- a/src/ace/theme/tm.css +++ b/src/ace/theme/tm.css @@ -116,4 +116,8 @@ .ace-tm .ace_marker-layer .ace_active_line { background: rgb(232, 242, 254); +} + +.ace-tm .ace_regex { + color: rgb(255, 0, 0) } \ No newline at end of file