browser/devtools/sourceeditor/codemirror/trailingspace.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/sourceeditor/codemirror/trailingspace.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,24 @@
     1.4 +(function(mod) {
     1.5 +  if (typeof exports == "object" && typeof module == "object") // CommonJS
     1.6 +    mod(require("../../lib/codemirror"));
     1.7 +  else if (typeof define == "function" && define.amd) // AMD
     1.8 +    define(["../../lib/codemirror"], mod);
     1.9 +  else // Plain browser env
    1.10 +    mod(CodeMirror);
    1.11 +})(function(CodeMirror) {
    1.12 +  CodeMirror.defineOption("showTrailingSpace", false, function(cm, val, prev) {
    1.13 +    if (prev == CodeMirror.Init) prev = false;
    1.14 +    if (prev && !val)
    1.15 +      cm.removeOverlay("trailingspace");
    1.16 +    else if (!prev && val)
    1.17 +      cm.addOverlay({
    1.18 +        token: function(stream) {
    1.19 +          for (var l = stream.string.length, i = l; i && /\s/.test(stream.string.charAt(i - 1)); --i) {}
    1.20 +          if (i > stream.pos) { stream.pos = i; return null; }
    1.21 +          stream.pos = l;
    1.22 +          return "trailingspace";
    1.23 +        },
    1.24 +        name: "trailingspace"
    1.25 +      });
    1.26 +  });
    1.27 +});

mercurial