]> git.donarmstrong.com Git - dactyl.git/blobdiff - common/modules/highlight.jsm
Import 1.0b7.1 supporting Firefox up to 8.*
[dactyl.git] / common / modules / highlight.jsm
index 35288942f54c24afb5b97cfa1e8b09a65fee63da..73b6b06ae7cf35ed166aa9b003e442d3285538bd 100644 (file)
@@ -33,6 +33,8 @@ Highlight.liveProperty = function (name, prop) {
                     h.style.css = h.css;
 
         this.style[prop || name] = this[prop || name];
+        if (this.onChange)
+            this.onChange();
     });
 }
 Highlight.liveProperty("agent");
@@ -100,7 +102,7 @@ var Highlights = Module("Highlight", {
     __iterator__: function () values(this.highlight).sort(function (a, b) String.localeCompare(a.class, b.class))
                                                     .iterValues(),
 
-    _create: function (agent, args) {
+    _create: function _create(agent, args) {
         let obj = Highlight.apply(Highlight, args);
 
         if (!isArray(obj.sites))
@@ -143,9 +145,9 @@ var Highlights = Module("Highlight", {
         return obj;
     },
 
-    get: function (k) this.highlight[k],
+    get: function get(k) this.highlight[k],
 
-    set: function (key, newStyle, force, append, extend) {
+    set: function set(key, newStyle, force, append, extend) {
         let [, class_, selectors] = key.match(/^([a-zA-Z_-]+)(.*)/);
 
         let highlight = this.highlight[key] || this._create(false, [key]);
@@ -181,7 +183,7 @@ var Highlights = Module("Highlight", {
      * Clears all highlighting rules. Rules with default values are
      * reset.
      */
-    clear: function () {
+    clear: function clear() {
         for (let [k, v] in Iterator(this.highlight))
             this.set(k, null, true);
     },
@@ -193,7 +195,7 @@ var Highlights = Module("Highlight", {
      * @param {Node} node
      * @param {string} group
      */
-    highlightNode: function (node, group, applyBindings) {
+    highlightNode: function highlightNode(node, group, applyBindings) {
         node.setAttributeNS(NS.uri, "highlight", group);
 
         let groups = group.split(" ");
@@ -214,7 +216,7 @@ var Highlights = Module("Highlight", {
      *
      * @param {string} class
      */
-    selector: function (class_)
+    selector: function selector(class_)
         let (self = this)
            class_.replace(/(^|[>\s])([A-Z][\w-]+)\b/g,
             function (m, n1, hl) n1 +
@@ -275,8 +277,9 @@ var Highlights = Module("Highlight", {
      * @param {string} css The rules to load. See {@link Highlights#css}.
      * @param {boolean} eager When true, load all provided rules immediately.
      */
-    loadCSS: function (css, eager) {
-        String.replace(css, this.groupRegexp, function (m, m1, m2) m1 + " " + m2.replace(/\n\s*/g, " "))
+    loadCSS: function loadCSS(css, eager) {
+        String.replace(css, /\\\n/g, "")
+              .replace(this.groupRegexp, function (m, m1, m2) m1 + " " + m2.replace(/\n\s*/g, " "))
               .split("\n").filter(function (s) /\S/.test(s) && !/^\s*\/\//.test(s))
               .forEach(function (highlight) {
 
@@ -291,7 +294,7 @@ var Highlights = Module("Highlight", {
     }
 }, {
 }, {
-    commands: function (dactyl, modules) {
+    commands: function initCommands(dactyl, modules) {
         const { autocommands, commands, completion, CommandOption, config, io } = modules;
 
         let lastScheme;
@@ -337,7 +340,7 @@ var Highlights = Module("Highlight", {
                 if (!modify && /&$/.test(key))
                     [clear, modify, key] = [true, true, key.replace(/&$/, "")];
 
-                dactyl.assert(!(clear && css), _("error.trailing"));
+                dactyl.assert(!(clear && css), _("error.trailingCharacters"));
 
                 if (!modify)
                     modules.commandline.commandOutput(
@@ -347,9 +350,11 @@ var Highlights = Module("Highlight", {
                             ([h.class,
                               <span style={"text-align: center; line-height: 1em;" + h.value + style}>XXX</span>,
                               template.map(h.extends, template.highlight),
-                              template.highlightRegexp(h.value, /\b[-\w]+(?=:)/g)]
-                                for (h in highlight)
-                                if (!key || h.class.indexOf(key) > -1))));
+                              template.highlightRegexp(h.value, /\b[-\w]+(?=:)|\/\*.*?\*\//g,
+                                                       function (match) <span highlight={match[0] == "/" ? "Comment" : "Key"}>{match}</span>)
+                             ]
+                             for (h in highlight)
+                             if (!key || h.class.indexOf(key) > -1))));
                 else if (!key && clear)
                     highlight.clear();
                 else if (key)
@@ -369,7 +374,10 @@ var Highlights = Module("Highlight", {
                     else if (args.completeArg == 1) {
                         let hl = highlight.get(args[0]);
                         if (hl)
-                            context.completions = [[hl.value, "Current Value"], [hl.defaultValue || "", "Default Value"]];
+                            context.completions = [
+                                [hl.value, _("option.currentValue")],
+                                [hl.defaultValue || "", _("option.defaultValue")]
+                            ];
                         context.fork("css", 0, completion, "css");
                     }
                 },
@@ -385,8 +393,8 @@ var Highlights = Module("Highlight", {
                             let group = args[0] && highlight.get(args[0]);
                             if (group)
                                 context.fork("extra", 0, this, function (context) [
-                                     [String(group.extends), "Current Value"],
-                                     [String(group.defaultExtends) || "", "Default Value"]
+                                     [String(group.extends), _("option.currentValue")],
+                                     [String(group.defaultExtends) || "", _("option.defaultValue")]
                                 ]);
                             context.fork("groups", 0, completion, "highlightGroup");
                         }
@@ -403,17 +411,22 @@ var Highlights = Module("Highlight", {
                 ]
             });
     },
-    completion: function (dactyl, modules) {
+    completion: function initCompletion(dactyl, modules) {
         const { completion, config, io } = modules;
+
         completion.colorScheme = function colorScheme(context) {
             let extRe = RegExp("\\." + config.fileExtension + "$");
 
             context.title = ["Color Scheme", "Runtime Path"];
             context.keys = { text: function (f) f.leafName.replace(extRe, ""), description: ".parent.path" };
-            context.completions = array.flatten(
-                io.getRuntimeDirectories("colors").map(
-                    function (dir) dir.readDirectory().filter(
-                        function (file) extRe.test(file.leafName))));
+            context.completions =
+                array.flatten(
+                        io.getRuntimeDirectories("colors").map(
+                            function (dir) dir.readDirectory().filter(
+                                function (file) extRe.test(file.leafName))))
+                     .concat([
+                        { leafName: "default", parent: { path: /*L*/"Revert to builtin colorscheme" } }
+                     ]);
 
         };
 
@@ -422,7 +435,7 @@ var Highlights = Module("Highlight", {
             context.completions = [[v.class, v.value] for (v in highlight)];
         };
     },
-    javascript: function (dactyl, modules, window) {
+    javascript: function initJavascript(dactyl, modules, window) {
         modules.JavaScript.setCompleter(["get", "set"].map(function (m) highlight[m]),
             [ function (context, obj, args) Iterator(highlight.highlight) ]);
         modules.JavaScript.setCompleter(["highlightNode"].map(function (m) highlight[m]),