Skip to content

Commit

Permalink
Implement code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminaaron committed Dec 21, 2024
1 parent 29261ad commit 0f8ff2d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/graph/Graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ export class Graph {
new Edge(connectionObj, this)
}

duplicateNode(nodeId) {
let node = this.nodesMap[nodeId]
let editorNode = this.editor.getNodeFromId(nodeId)
let newNode = createNode(node.constructor.name, node.name, Number(editorNode.pos_x) + 30, Number(editorNode.pos_y) + 30, this.editor, this.nodesMap)
if (node.isInput()) newNode.setValue(node.getValue())
}

removeEdge(connection) {
let edgeId = buildEdgeId(connection)
delete this.edgesMap[edgeId]
Expand Down
7 changes: 6 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,13 @@
editor.on("contextmenu", event => {
if (event.target.tagName !== "DIV") return // edges are "path"
if (event.target.className.includes("title-box")) {
let nodeDivId = event.target.parentElement.parentElement.parentElement.id
setupNodeHeaderContextMenu(event, (action, label, x, y) => {
// TODO
switch (action) {
case "DuplicateNodeAction":
graph.duplicateNode(nodeDivId.split("-")[1])
break
}
})
return
}
Expand Down

0 comments on commit 0f8ff2d

Please sign in to comment.