From bb295a58d9a4cdfab8c4eedb51d57e46907eed26 Mon Sep 17 00:00:00 2001
From: Valentin Perrelle <valentin.perrelle@cea.fr>
Date: Mon, 28 Aug 2023 16:59:52 +0200
Subject: [PATCH] [Ivette] Dive: edge selection

---
 ivette/src/frama-c/plugins/dive/index.tsx | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/ivette/src/frama-c/plugins/dive/index.tsx b/ivette/src/frama-c/plugins/dive/index.tsx
index 77dd2a9f9aa..6abe4e56270 100644
--- a/ivette/src/frama-c/plugins/dive/index.tsx
+++ b/ivette/src/frama-c/plugins/dive/index.tsx
@@ -139,6 +139,7 @@ class Dive {
     // Add new listeners
     enableDoubleClickEvents(this.cy);
     this.cy.on('click', 'node', (event) => this.clickNode(event.target));
+    this.cy.on('click', 'edge', (event) => this.clickEdge(event.target));
     this.cy.on('double-click', '$node > node', // compound nodes
       (event) => this.doubleClickNode(event.target));
 
@@ -527,6 +528,18 @@ class Dive {
     node.unselectify();
   }
 
+  async clickEdge(edge: Cytoscape.EdgeSingular): Promise<void> {
+    // Unselect everything
+    this.cy.$(':selected').forEach(unselect);
+    this.cy.$('.multiple-selection').removeClass('multiple-selection');
+    this.cy.$('.selection').removeClass('selection');
+
+    // Update Ivette selection
+    const origins = edge.data()?.origins;
+    if (origins && origins.length)
+      this.onSelect?.(origins);
+  }
+
   doubleClickNode(node: Cytoscape.NodeSingular): void {
     this.cy.animate({ fit: { eles: node, padding: 10 } });
   }
-- 
GitLab