From 0ddefeeaefd3558edadd159f483ff7d3d3df7e38 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Tue, 16 Jul 2019 17:28:47 +0000 Subject: [PATCH] Use attributes for class selection --- Editor.js | 44 +++++++++++++++++++++++++------------------- List.js | 5 +---- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/Editor.js b/Editor.js index 8597af0..07c3624 100644 --- a/Editor.js +++ b/Editor.js @@ -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); diff --git a/List.js b/List.js index 00413f5..78b22b5 100644 --- a/List.js +++ b/List.js @@ -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;