comparison .cms/lib/codemirror/addon/hint/css-hint.js @ 0:78edf6b517a0 draft

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