trailingspace.js 528 B

123456789101112131415
  1. CodeMirror.defineOption("showTrailingSpace", false, function(cm, val, prev) {
  2. if (prev == CodeMirror.Init) prev = false;
  3. if (prev && !val)
  4. cm.removeOverlay("trailingspace");
  5. else if (!prev && val)
  6. cm.addOverlay({
  7. token: function(stream) {
  8. for (var l = stream.string.length, i = l; i && /\s/.test(stream.string.charAt(i - 1)); --i) {}
  9. if (i > stream.pos) { stream.pos = i; return null; }
  10. stream.pos = l;
  11. return "trailingspace";
  12. },
  13. name: "trailingspace"
  14. });
  15. });