Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

67 řádky
2.5KB

  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: https://codemirror.net/LICENSE
  3. (function(mod) {
  4. if (typeof exports == "object" && typeof module == "object") // CommonJS
  5. mod(require("../../lib/codemirror"), require("../../mode/css/css"));
  6. else if (typeof define == "function" && define.amd) // AMD
  7. define(["../../lib/codemirror", "../../mode/css/css"], mod);
  8. else // Plain browser env
  9. mod(CodeMirror);
  10. })(function(CodeMirror) {
  11. "use strict";
  12. var pseudoClasses = {"active":1, "after":1, "before":1, "checked":1, "default":1,
  13. "disabled":1, "empty":1, "enabled":1, "first-child":1, "first-letter":1,
  14. "first-line":1, "first-of-type":1, "focus":1, "hover":1, "in-range":1,
  15. "indeterminate":1, "invalid":1, "lang":1, "last-child":1, "last-of-type":1,
  16. "link":1, "not":1, "nth-child":1, "nth-last-child":1, "nth-last-of-type":1,
  17. "nth-of-type":1, "only-of-type":1, "only-child":1, "optional":1, "out-of-range":1,
  18. "placeholder":1, "read-only":1, "read-write":1, "required":1, "root":1,
  19. "selection":1, "target":1, "valid":1, "visited":1
  20. };
  21. CodeMirror.registerHelper("hint", "css", function(cm) {
  22. var cur = cm.getCursor(), token = cm.getTokenAt(cur);
  23. var inner = CodeMirror.innerMode(cm.getMode(), token.state);
  24. if (inner.mode.name != "css") return;
  25. if (token.type == "keyword" && "!important".indexOf(token.string) == 0)
  26. return {list: ["!important"], from: CodeMirror.Pos(cur.line, token.start),
  27. to: CodeMirror.Pos(cur.line, token.end)};
  28. var start = token.start, end = cur.ch, word = token.string.slice(0, end - start);
  29. if (/[^\w$_-]/.test(word)) {
  30. word = ""; start = end = cur.ch;
  31. }
  32. var spec = CodeMirror.resolveMode("text/css");
  33. var result = [];
  34. function add(keywords) {
  35. for (var name in keywords)
  36. if (!word || name.lastIndexOf(word, 0) == 0)
  37. result.push(name);
  38. }
  39. var st = inner.state.state;
  40. if (st == "pseudo" || token.type == "variable-3") {
  41. add(pseudoClasses);
  42. } else if (st == "block" || st == "maybeprop") {
  43. add(spec.propertyKeywords);
  44. } else if (st == "prop" || st == "parens" || st == "at" || st == "params") {
  45. add(spec.valueKeywords);
  46. add(spec.colorKeywords);
  47. } else if (st == "media" || st == "media_parens") {
  48. add(spec.mediaTypes);
  49. add(spec.mediaFeatures);
  50. }
  51. if (result.length) return {
  52. list: result,
  53. from: CodeMirror.Pos(cur.line, start),
  54. to: CodeMirror.Pos(cur.line, end)
  55. };
  56. });
  57. });