trailingspace.js 1003 B

123456789101112131415161718192021222324252627
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: http://codemirror.net/LICENSE
  3. (function(mod) {
  4. if (typeof exports == "object" && typeof module == "object") // CommonJS
  5. mod(require("../../lib/codemirror"));
  6. else if (typeof define == "function" && define.amd) // AMD
  7. define(["../../lib/codemirror"], mod);
  8. else // Plain browser env
  9. mod(CodeMirror);
  10. })(function(CodeMirror) {
  11. CodeMirror.defineOption("showTrailingSpace", false, function(cm, val, prev) {
  12. if (prev == CodeMirror.Init) prev = false;
  13. if (prev && !val)
  14. cm.removeOverlay("trailingspace");
  15. else if (!prev && val)
  16. cm.addOverlay({
  17. token: function(stream) {
  18. for (var l = stream.string.length, i = l; i && /\s/.test(stream.string.charAt(i - 1)); --i) {}
  19. if (i > stream.pos) { stream.pos = i; return null; }
  20. stream.pos = l;
  21. return "trailingspace";
  22. },
  23. name: "trailingspace"
  24. });
  25. });
  26. });