David Catuhe 5 years ago
parent
commit
4f6b802e7d
2 changed files with 13 additions and 4 deletions
  1. 1 1
      nodeEditor/src/diagram/graphNode.ts
  2. 12 3
      nodeEditor/src/graphEditor.tsx

+ 1 - 1
nodeEditor/src/diagram/graphNode.ts

@@ -309,7 +309,7 @@ export class GraphNode {
         }
 
         const indexInSelection = this._ownerCanvas.selectedNodes.indexOf(this) ;
-        if (indexInSelection=== -1) {
+        if (indexInSelection === -1) {
             this._globalState.onSelectionChangedObservable.notifyObservers(this);
         } else if (evt.ctrlKey) {
             this.isSelected = false;

+ 12 - 3
nodeEditor/src/graphEditor.tsx

@@ -243,7 +243,6 @@ export class GraphEditor extends React.Component<IGraphEditorProps, IGraphEditor
                     newFrame.y = currentY;
 
                     // Paste nodes
-
                     if (this._copiedFrame.nodes.length) {
                         currentX = newFrame.x + this._copiedFrame.nodes[0].x - this._copiedFrame.x;
                         currentY = newFrame.y + this._copiedFrame.nodes[0].y - this._copiedFrame.y;
@@ -253,6 +252,9 @@ export class GraphEditor extends React.Component<IGraphEditorProps, IGraphEditor
                     if (this._copiedFrame.isCollapsed) {
                         newFrame.isCollapsed = true;
                     }
+
+                    // Select
+                    this.props.globalState.onSelectionChangedObservable.notifyObservers(newFrame);
                     return;
                 }
 
@@ -261,7 +263,7 @@ export class GraphEditor extends React.Component<IGraphEditorProps, IGraphEditor
                 }
 
                 let currentX = (this._mouseLocationX - rootElement.offsetLeft - this._graphCanvas.x - this.NodeWidth) / zoomLevel;
-                this.pasteSelection(this._copiedNodes, currentX, currentY);
+                this.pasteSelection(this._copiedNodes, currentX, currentY, true);
             }
 
         }, false);
@@ -310,7 +312,7 @@ export class GraphEditor extends React.Component<IGraphEditorProps, IGraphEditor
         done[nodeIndex] = true;
     }
 
-    pasteSelection(copiedNodes: GraphNode[], currentX: number, currentY: number) {
+    pasteSelection(copiedNodes: GraphNode[], currentX: number, currentY: number, selectNew = false) {
 
         let originalNode: Nullable<GraphNode> = null;
 
@@ -319,6 +321,9 @@ export class GraphEditor extends React.Component<IGraphEditorProps, IGraphEditor
         // Copy to prevent recursive side effects while creating nodes.
         copiedNodes = copiedNodes.slice();
 
+        // Cancel selection        
+        this.props.globalState.onSelectionChangedObservable.notifyObservers(null);
+
         // Create new nodes
         for (var node of copiedNodes) {
             let block = node.block;
@@ -351,6 +356,10 @@ export class GraphEditor extends React.Component<IGraphEditorProps, IGraphEditor
             newNode.cleanAccumulation();
 
             newNodes.push(newNode);
+
+            if (selectNew) {
+                this.props.globalState.onSelectionChangedObservable.notifyObservers(newNode);
+            }
         }
 
         // Relink