Use attributes for class selection

This commit is contained in:
Ian Gulliver
2019-07-16 17:28:47 +00:00
parent a66bee672d
commit 0ddefeeaef
2 changed files with 26 additions and 23 deletions

View File

@@ -106,36 +106,40 @@ class Editor extends List {
addLinkAfter(...rest) {
if (this.mayAdd(EditorLink)) {
return EditorLink.addAfter(this.container_, this.getSelected(),
this.queryEntries('.highlight', EditorNode),
...rest);
return EditorLink.addAfter(
this.container_, this.getSelected(),
this.queryEntries('.highlight[data-arch-class="EditorNode"]'),
...rest);
}
return null;
}
addLinkBefore(...rest) {
if (this.mayAdd(EditorLink)) {
return EditorLink.addBefore(this.container_, this.getSelected(),
this.queryEntries('.highlight', EditorNode),
...rest);
return EditorLink.addBefore(
this.container_, this.getSelected(),
this.queryEntries('.highlight[data-arch-class="EditorNode"]'),
...rest);
}
return null;
}
addGroupAfter(...rest) {
if (this.mayAdd(EditorGroup)) {
return EditorGroup.addAfter(this.container_, this.getSelected(),
this.queryEntries('.highlight', EditorNode),
...rest);
return EditorGroup.addAfter(
this.container_, this.getSelected(),
this.queryEntries('.highlight[data-arch-class="EditorNode"]'),
...rest);
}
return null;
}
addGroupBefore(...rest) {
if (this.mayAdd(EditorGroup)) {
return EditorGroup.addBefore(this.container_, this.getSelected(),
this.queryEntries('.highlight', EditorNode),
...rest);
return EditorGroup.addBefore(
this.container_, this.getSelected(),
this.queryEntries('.highlight[data-arch-class="EditorNode"]'),
...rest);
}
return null;
}
@@ -149,24 +153,26 @@ class Editor extends List {
addTagAfter(...rest) {
if (this.mayAdd(EditorTag)) {
return EditorTag.addAfter(this.container_, this.getSelected(),
this.queryEntries('.highlight', EditorNode),
...rest);
return EditorTag.addAfter(
this.container_, this.getSelected(),
this.queryEntries('.highlight[data-arch-class="EditorNode"]'),
...rest);
}
return null;
}
addTagBefore(...rest) {
if (this.mayAdd(EditorTag)) {
return EditorTag.addBefore(this.container_, this.getSelected(),
this.queryEntries('.highlight', EditorNode),
...rest);
return EditorTag.addBefore(
this.container_, this.getSelected(),
this.queryEntries('.highlight[data-arch-class="EditorNode"]'),
...rest);
}
return null;
}
updateNodes(oldLabel, newLabel) {
let nodes = this.queryEntries('[data-arch-class="EditorNode"]', EditorNode);
let nodes = this.queryEntries('[data-arch-class="EditorNode"]');
for (let node of nodes) {
if (node.getLabel() == oldLabel) {
node.setLabel(newLabel);

View File

@@ -14,15 +14,12 @@ class List {
return ret;
}
queryEntries(query, type) {
queryEntries(query) {
let ret = [];
for (let elem of this.container_.querySelectorAll(query)) {
if (!elem.xArchObj) {
continue;
}
if (type && !(elem.xArchObj instanceof type)) {
continue;
}
ret.push(elem.xArchObj);
}
return ret;