Skip to content

Commit 9e36804

Browse files
committed
feat: do not lose selection on unselect
1 parent 3c5ac31 commit 9e36804

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

graph.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ function highlightElement(event) {
164164
// Single tap is too error prone
165165
if (event.type === "dbltap") {
166166
unhighlightNode(null, true);
167+
cy.nodes().selectify();
168+
cy.nodes().filter(":selected").unselect();
169+
cy.nodes().unselectify();
167170
}
168171
else {
169172
console.log("No-op: single tap on background");
@@ -175,22 +178,20 @@ function highlightElement(event) {
175178
if (event.type === "dbltap") {
176179
highlightNode(node);
177180
}
178-
else if (event.type === "select") {
181+
else if (event.type === "tap") {
179182
showNodeDetails(node);
180183
}
181-
} else if (event.target.group() === "edges") {
182-
const edge = event.target;
183-
if (event.type === "select") {
184-
// do nothing special
185-
}
186-
else if (event.type === "dbltap") {
187-
highlightEdge(edge);
188-
}
184+
cy.nodes().selectify();
185+
cy.nodes().filter(":selected").unselect();
186+
node.select();
187+
cy.nodes().unselectify();
189188
}
190189
}
191190
}
192191

193192
function unhighlightNode(event, unselect) {
193+
if (! highlighted_node)
194+
return;
194195
// Swap out center/uncenter buttons
195196
const centerButton = document.getElementById("center_button");
196197
const uncenterButton = document.getElementById("uncenter_button");
@@ -379,11 +380,12 @@ function create_cy_elements(data, style) {
379380
// store the meta_node, since we need to remove it when highlighting nodes
380381
meta_node = cy.$("#simulators");
381382
meta_node_edges = meta_node.connectedEdges();
382-
cy.on("select tap dbltap", highlightElement);
383+
cy.on("tap dbltap", highlightElement);
383384
//
384385
// if a user drags a node, we want to remember this
385386
cy.on("drag", "node", store_positions);
386387
cy.$("#simulators").select();
388+
cy.nodes().unselectify(); // We handle selection manually in highlightNode
387389
selectionChanged();
388390
}
389391

0 commit comments

Comments
 (0)