|
13 | 13 |
|
14 | 14 | var Pos = CodeMirror.Pos; |
15 | 15 |
|
| 16 | + function matches(hint, typed, matchInMiddle) { |
| 17 | + if (matchInMiddle) return hint.indexOf(typed) >= 0; |
| 18 | + else return hint.lastIndexOf(typed, 0) == 0; |
| 19 | + } |
| 20 | + |
16 | 21 | function getHints(cm, options) { |
17 | 22 | var tags = options && options.schemaInfo; |
18 | 23 | var quote = (options && options.quoteChar) || '"'; |
| 24 | + var matchInMiddle = options && options.matchInMiddle; |
19 | 25 | if (!tags) return; |
20 | 26 | var cur = cm.getCursor(), token = cm.getTokenAt(cur); |
21 | 27 | if (token.end > cur.ch) { |
|
45 | 51 | var cx = inner.state.context, curTag = cx && tags[cx.tagName]; |
46 | 52 | var childList = cx ? curTag && curTag.children : tags["!top"]; |
47 | 53 | if (childList && tagType != "close") { |
48 | | - for (var i = 0; i < childList.length; ++i) if (!prefix || childList[i].lastIndexOf(prefix, 0) == 0) |
| 54 | + for (var i = 0; i < childList.length; ++i) if (!prefix || matches(childList[i], prefix, matchInMiddle)) |
49 | 55 | result.push("<" + childList[i]); |
50 | 56 | } else if (tagType != "close") { |
51 | 57 | for (var name in tags) |
52 | | - if (tags.hasOwnProperty(name) && name != "!top" && name != "!attrs" && (!prefix || name.lastIndexOf(prefix, 0) == 0)) |
| 58 | + if (tags.hasOwnProperty(name) && name != "!top" && name != "!attrs" && (!prefix || matches(name, prefix, matchInMiddle))) |
53 | 59 | result.push("<" + name); |
54 | 60 | } |
55 | | - if (cx && (!prefix || tagType == "close" && cx.tagName.lastIndexOf(prefix, 0) == 0)) |
| 61 | + if (cx && (!prefix || tagType == "close" && matches(cx.tagName, prefix, matchInMiddle))) |
56 | 62 | result.push("</" + cx.tagName + ">"); |
57 | 63 | } else { |
58 | 64 | // Attribute completion |
|
88 | 94 | } |
89 | 95 | replaceToken = true; |
90 | 96 | } |
91 | | - for (var i = 0; i < atValues.length; ++i) if (!prefix || atValues[i].lastIndexOf(prefix, 0) == 0) |
| 97 | + for (var i = 0; i < atValues.length; ++i) if (!prefix || matches(atValues[i], prefix, matchInMiddle)) |
92 | 98 | result.push(quote + atValues[i] + quote); |
93 | 99 | } else { // An attribute name |
94 | 100 | if (token.type == "attribute") { |
95 | 101 | prefix = token.string; |
96 | 102 | replaceToken = true; |
97 | 103 | } |
98 | | - for (var attr in attrs) if (attrs.hasOwnProperty(attr) && (!prefix || attr.lastIndexOf(prefix, 0) == 0)) |
| 104 | + for (var attr in attrs) if (attrs.hasOwnProperty(attr) && (!prefix || matches(attr, prefix, matchInMiddle))) |
99 | 105 | result.push(attr); |
100 | 106 | } |
101 | 107 | } |
|
0 commit comments