Skip to content

Commit 9d40fc6

Browse files
committed
emit onNodeHoverChange and set hovered node for renderer for newly added nodes in interactive, fixes Yonava#10
1 parent 05aee60 commit 9d40fc6

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

client/src/graphs/base/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,14 @@ export const useBaseGraph = (
265265

266266
updateAggregator.push(liftHoveredNodeToTop);
267267

268+
/**
269+
* Sets the current hovered node (e.g. when adding a new node)
270+
* @param node - the node to set as hovered
271+
*/
272+
const setCurrHoveredNode = (node: GNode | undefined) => {
273+
currHoveredNode = node;
274+
};
275+
268276
/**
269277
* load a graph state into the graph
270278
* @param graphState - the graph state to load (nodes and edges)
@@ -354,6 +362,7 @@ export const useBaseGraph = (
354362
* a mapping of all graph events to a set of their callback functions
355363
*/
356364
eventBus,
365+
setCurrHoveredNode,
357366
subscribe,
358367
unsubscribe,
359368
emit,

client/src/graphs/plugins/interactive/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ export const useInteractive = (graph: BaseGraph) => {
1313

1414
const nodeAdded = graph.addNode(coords);
1515
if (!nodeAdded) return;
16-
setTimeout(() => graph.updateGraphAtMousePosition(event), 10);
16+
setTimeout(() => {
17+
graph.updateGraphAtMousePosition(event);
18+
19+
// The cursor is now hovering this new node
20+
graph.setCurrHoveredNode(nodeAdded satisfies GNode);
21+
graph.emit('onNodeHoverChange', nodeAdded satisfies GNode, undefined);
22+
}, 10);
1723
};
1824

1925
const doesEdgeConformToRules = (fromNode: GNode, toNode: GNode) => {

0 commit comments

Comments
 (0)