| 1 |
(function () { |
| 2 |
"use strict"; |
| 3 |
|
| 4 |
function getHints(cm) { |
| 5 |
var cur = cm.getCursor(), token = cm.getTokenAt(cur); |
| 6 |
var inner = CodeMirror.innerMode(cm.getMode(), token.state); |
| 7 |
if (inner.mode.name != "css") return; |
| 8 |
|
| 9 |
// If it's not a 'word-style' token, ignore the token. |
| 10 |
if (!/^[\w$_-]*$/.test(token.string)) { |
| 11 |
token = { |
| 12 |
start: cur.ch, end: cur.ch, string: "", state: token.state, |
| 13 |
type: null |
| 14 |
}; |
| 15 |
var stack = token.state.stack; |
| 16 |
var lastToken = stack && stack.length > 0 ? stack[stack.length - 1] : ""; |
| 17 |
if (token.string == ":" || lastToken.indexOf("property") == 0) |
| 18 |
token.type = "variable"; |
| 19 |
else if (token.string == "{" || lastToken.indexOf("rule") == 0) |
| 20 |
token.type = "property"; |
| 21 |
} |
| 22 |
|
| 23 |
if (!token.type) |
| 24 |
return; |
| 25 |
|
| 26 |
var spec = CodeMirror.resolveMode("text/css"); |
| 27 |
var keywords = null; |
| 28 |
if (token.type.indexOf("property") == 0) |
| 29 |
keywords = spec.propertyKeywords; |
| 30 |
else if (token.type.indexOf("variable") == 0) |
| 31 |
keywords = spec.valueKeywords; |
| 32 |
|
| 33 |
if (!keywords) |
| 34 |
return; |
| 35 |
|
| 36 |
var result = []; |
| 37 |
for (var name in keywords) { |
| 38 |
if (name.indexOf(token.string) == 0 /* > -1 */) |
| 39 |
result.push(name); |
| 40 |
} |
| 41 |
|
| 42 |
return { |
| 43 |
list: result, |
| 44 |
from: CodeMirror.Pos(cur.line, token.start), |
| 45 |
to: CodeMirror.Pos(cur.line, token.end) |
| 46 |
}; |
| 47 |
} |
| 48 |
|
| 49 |
CodeMirror.registerHelper("hint", "css", getHints); |
| 50 |
})(); |
| 51 |
|