From 4d7533a7c09842b4e7d7088099159d65311131c0 Mon Sep 17 00:00:00 2001 From: Paul Dubs Date: Mon, 15 Jul 2024 15:42:48 +0200 Subject: [PATCH 1/3] Make copy & paste work for attached nodes --- src/commands/NodeActionCommands.tsx | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/commands/NodeActionCommands.tsx b/src/commands/NodeActionCommands.tsx index 13e73a4f..a4701b15 100644 --- a/src/commands/NodeActionCommands.tsx +++ b/src/commands/NodeActionCommands.tsx @@ -512,13 +512,33 @@ export function addNodeActionCommands( label: trans.__('Add Comment') }); + function selectAllRelevantNodes(widget: XircuitsPanel){ + widget.xircuitsApp.getDiagramEngine().getModel().getSelectedEntities().forEach(entity => { + if(entity.getType() === 'custom-node'){ + const node = (entity as CustomNodeModel); + // Find links to attached node and copy them too + Object.values(node.getPorts()).forEach(port => { + Object.values(port.getLinks()).forEach(link => { + const parentNode = link.getSourcePort().getParent(); + if(parentNode.getOptions()?.extras?.attached){ + parentNode.setSelected(true); + link.setSelected(true); + } + }) + }) + } + }); + + return widget.xircuitsApp.getDiagramEngine().getModel().getSelectedEntities(); + } + function cutNode(): void { const widget = tracker.currentWidget?.content as XircuitsPanel; if (!widget) return; const engine = widget.xircuitsApp.getDiagramEngine(); - const selected = widget.xircuitsApp.getDiagramEngine().getModel().getSelectedEntities() + const selected = selectAllRelevantNodes(widget); const copies = selected.map(entity => entity.serialize() ); @@ -536,9 +556,7 @@ export function addNodeActionCommands( if (!widget) return; - const copies = widget.xircuitsApp.getDiagramEngine().getModel().getSelectedEntities().map(entity => - entity.serialize(), - ); + const copies = selectAllRelevantNodes(widget).map(entity => entity.serialize()); localStorage.setItem('clipboard', JSON.stringify(copies)); } @@ -658,7 +676,7 @@ export function addNodeActionCommands( clipboardLinks.forEach(serializedLink => { const newSourceID = idMap[serializedLink.sourcePort]; const newTargetID = idMap[serializedLink.targetPort]; - + if (newSourceID && newTargetID) { const { sourcePort, targetPort } = getSourceAndTargetPorts(model, newSourceID, newTargetID); if(sourcePort && targetPort) recreateLink(engine, model, serializedLink, sourcePort, targetPort, mousePosition, centerX, centerY); From c9fa2ea403b4dbe35ff615077ac9e499edc4cf24 Mon Sep 17 00:00:00 2001 From: Paul Dubs Date: Mon, 15 Jul 2024 15:43:03 +0200 Subject: [PATCH 2/3] Remove left-over debug logging --- src/dialog/LiteralInputDialog.tsx | 1 - src/tray_library/GeneralComponentLib.tsx | 2 -- 2 files changed, 3 deletions(-) diff --git a/src/dialog/LiteralInputDialog.tsx b/src/dialog/LiteralInputDialog.tsx index d1ef2fe0..ba66cfc2 100644 --- a/src/dialog/LiteralInputDialog.tsx +++ b/src/dialog/LiteralInputDialog.tsx @@ -63,7 +63,6 @@ export const LiteralInputDialog = ({ title, oldValue, type, inputType, attached, const InputValueDialog = () => { const [attach, setAttach] = useState(attached || false) const InputComponent = inputComponents[inputType === 'textarea' ? inputType.toLowerCase() : type.toLowerCase()]; - console.log("me seeks", InputComponent, showAttachOption); // The `type` prop is now passed to all components const extraProps = { type, inputType }; diff --git a/src/tray_library/GeneralComponentLib.tsx b/src/tray_library/GeneralComponentLib.tsx index a3c6a688..7e7e924a 100644 --- a/src/tray_library/GeneralComponentLib.tsx +++ b/src/tray_library/GeneralComponentLib.tsx @@ -24,8 +24,6 @@ export async function handleLiteralInput(nodeName, nodeData, inputValue = "", ty let attached = false; do { - console.log("valuexxx", nodeConnections); - const isCreatingNewNode = nodeConnections === 0; let dialogOptions = inputDialog({ title, oldValue: inputValue, type, attached: (nodeData.extras?.attached || false ), showAttachOption: !isCreatingNewNode}); let dialogResult = await showFormDialog(dialogOptions); From c5a4db3be9f187e8253685735fff308d9b5df7b3 Mon Sep 17 00:00:00 2001 From: Paul Dubs Date: Mon, 15 Jul 2024 15:57:56 +0200 Subject: [PATCH 3/3] Bugfix: Don't trigger `enter` behavior just because there is the `attachNode` checkbox --- src/dialog/FormDialog.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dialog/FormDialog.tsx b/src/dialog/FormDialog.tsx index 55fc36b0..bf3eb577 100644 --- a/src/dialog/FormDialog.tsx +++ b/src/dialog/FormDialog.tsx @@ -106,9 +106,9 @@ const preventDefaultDialogHandler = ( event.stopPropagation(); event.preventDefault(); } - // When 'Enter' key is pressed while on input dialog and the input isn't Literal Chat, force focus to submit button + // When 'Enter' key is pressed while on input dialog and the input isn't Literal Chat or the attached checkbox, force focus to submit button const dialogInput = dialog.node.getElementsByTagName('input')[0]; - if (dialogInput && dialogInput.name !== 'messages') { + if (dialogInput && !['messages', 'attachNode'].includes(dialogInput.name)) { await defaultButton.focus(); } } else {