Skip to content

Commit 77605d5

Browse files
committed
[xml-hint addon] Support attributes that apply to all tags
1 parent f956a0d commit 77605d5

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

addon/hint/xml-hint.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,16 @@
3939
} else {
4040
// Attribute completion
4141
var curTag = tags[inner.state.tagName], attrs = curTag && curTag.attrs;
42-
if (!attrs) return;
42+
var globalAttrs = tags["!attrs"];
43+
if (!attrs && !globalAttrs) return;
44+
if (!attrs) {
45+
attrs = globalAttrs;
46+
} else if (globalAttrs) { // Combine tag-local and global attributes
47+
var set = {};
48+
for (var nm in globalAttrs) if (globalAttrs.hasOwnProperty(nm)) set[nm] = globalAttrs[nm];
49+
for (var nm in attrs) if (attrs.hasOwnProperty(nm)) set[nm] = attrs[nm];
50+
attrs = set;
51+
}
4352
if (token.type == "string" || token.string == "=") { // A value
4453
var before = cm.getRange(Pos(cur.line, Math.max(0, cur.ch - 60)),
4554
Pos(cur.line, token.type == "string" ? token.start : token.end));

demo/xmlcomplete.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ <h2>XML Autocomplete Demo</h2>
5252

5353
var tags = {
5454
"!top": ["top"],
55+
"!attrs": {
56+
id: null,
57+
class: ["A", "B", "C"]
58+
},
5559
top: {
5660
attrs: {
5761
lang: ["en", "de", "fr", "nl"],

0 commit comments

Comments
 (0)