This is an automated email from the ASF dual-hosted git repository.

marat pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karavan.git

commit 504673cf8b77aaba3b1be2652828d7f14c935429
Author: Marat Gubaidullin <marat.gubaidul...@gmail.com>
AuthorDate: Mon Jan 23 10:55:47 2023 -0500

    Copy/Paste Route
---
 .../src/designer/route/RouteDesignerLogic.tsx      | 53 ++++++++++++----------
 1 file changed, 30 insertions(+), 23 deletions(-)

diff --git a/karavan-designer/src/designer/route/RouteDesignerLogic.tsx 
b/karavan-designer/src/designer/route/RouteDesignerLogic.tsx
index 168112c0..18b2ce3c 100644
--- a/karavan-designer/src/designer/route/RouteDesignerLogic.tsx
+++ b/karavan-designer/src/designer/route/RouteDesignerLogic.tsx
@@ -69,7 +69,6 @@ export class RouteDesignerLogic {
     }
 
     handleKeyDown = (event: KeyboardEvent) => {
-        const {integration, selectedUuids, clipboardSteps} = 
this.routeDesigner.state;
         if ((event.shiftKey)) {
             this.routeDesigner.setState({shiftKeyPressed: true});
         }
@@ -77,28 +76,9 @@ export class RouteDesignerLogic {
             if (['BODY', 
'MAIN'].includes(window.document.activeElement.tagName)) {
                 let charCode = String.fromCharCode(event.which).toLowerCase();
                 if ((event.ctrlKey || event.metaKey) && charCode === 'c') {
-                    const steps: CamelElement[] = []
-                    selectedUuids.forEach(selectedUuid => {
-                        const selectedElement = 
CamelDefinitionApiExt.findElementInIntegration(integration, selectedUuid);
-                        if (selectedElement) {
-                            steps.push(selectedElement);
-                        }
-                    })
-                    this.saveToClipboard(steps);
+                    this.copyToClipboard();
                 } else if ((event.ctrlKey || event.metaKey) && charCode === 
'v') {
-                    if (clipboardSteps.length === 1 && 
clipboardSteps[0]?.dslName === 'FromDefinition') {
-                        const clone = CamelUtil.cloneStep(clipboardSteps[0], 
true);
-                        const route = 
CamelDefinitionApi.createRouteDefinition({from: clone});
-                        this.addStep(route, '', 0)
-                    } else if (selectedUuids.length === 1) {
-                        const targetMeta = 
CamelDefinitionApiExt.findElementMetaInIntegration(integration, 
selectedUuids[0]);
-                        clipboardSteps.reverse().forEach(clipboardStep => {
-                            if (clipboardStep && targetMeta.parentUuid) {
-                                const clone = 
CamelUtil.cloneStep(clipboardStep, true);
-                                this.addStep(clone, targetMeta.parentUuid, 
targetMeta.position);
-                            }
-                        })
-                    }
+                    this.pasteFromClipboard();
                 }
             }
         } else {
@@ -121,7 +101,15 @@ export class RouteDesignerLogic {
         }
     }
 
-    saveToClipboard = (steps: CamelElement[]): void => {
+    copyToClipboard = (): void => {
+        const {integration, selectedUuids} = this.routeDesigner.state;
+        const steps: CamelElement[] = []
+        selectedUuids.forEach(selectedUuid => {
+            const selectedElement = 
CamelDefinitionApiExt.findElementInIntegration(integration, selectedUuid);
+            if (selectedElement) {
+                steps.push(selectedElement);
+            }
+        })
         if (steps.length >0) {
             this.routeDesigner.setState(prevState => ({
                 key: Math.random().toString(),
@@ -129,6 +117,25 @@ export class RouteDesignerLogic {
             }));
         }
     }
+    pasteFromClipboard = (): void => {
+        const {integration, selectedUuids, clipboardSteps} = 
this.routeDesigner.state;
+        if (clipboardSteps.length === 1 && clipboardSteps[0]?.dslName === 
'FromDefinition') {
+            const clone = CamelUtil.cloneStep(clipboardSteps[0], true);
+            const route = CamelDefinitionApi.createRouteDefinition({from: 
clone});
+            this.addStep(route, '', 0)
+        } else if (clipboardSteps.length === 1 && clipboardSteps[0]?.dslName 
=== 'RouteDefinition') {
+            const clone = CamelUtil.cloneStep(clipboardSteps[0], true);
+            this.addStep(clone, '', 0)
+        } else if (selectedUuids.length === 1) {
+            const targetMeta = 
CamelDefinitionApiExt.findElementMetaInIntegration(integration, 
selectedUuids[0]);
+            clipboardSteps.reverse().forEach(clipboardStep => {
+                if (clipboardStep && targetMeta.parentUuid) {
+                    const clone = CamelUtil.cloneStep(clipboardStep, true);
+                    this.addStep(clone, targetMeta.parentUuid, 
targetMeta.position);
+                }
+            })
+        }
+    }
 
     onCommand = (command: Command) => {
         switch (command.command){

Reply via email to