From a392beb1052504668bc72189d9b05f2699135d55 Mon Sep 17 00:00:00 2001
From: Paul Kaplan <pkaplan@media.mit.edu>
Date: Mon, 4 Dec 2017 13:31:09 -0500
Subject: [PATCH] Keep the block centered on the workspace

---
 src/containers/custom-procedures.jsx | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/containers/custom-procedures.jsx b/src/containers/custom-procedures.jsx
index d594aba2b..002a5c4b7 100644
--- a/src/containers/custom-procedures.jsx
+++ b/src/containers/custom-procedures.jsx
@@ -39,16 +39,18 @@ class CustomProcedures extends React.Component {
 
         // Create the procedure declaration block for editing the mutation.
         this.mutationRoot = this.workspace.newBlock('procedures_declaration');
-        this.workspace.addChangeListener(() => this.mutationRoot.onChangeFn());
+        this.workspace.addChangeListener(() => {
+            this.mutationRoot.onChangeFn();
+            // Keep the block centered on the workspace
+            const metrics = this.workspace.getMetrics();
+            const {x, y} = this.mutationRoot.getRelativeToSurfaceXY();
+            const dx = (metrics.viewWidth / 2) - (this.mutationRoot.width / 2) - x;
+            const dy = (metrics.viewHeight / 2) - (this.mutationRoot.height / 2) - y;
+            this.mutationRoot.moveBy(dx, dy);
+        });
         this.mutationRoot.domToMutation(this.props.mutator);
         this.mutationRoot.initSvg();
         this.mutationRoot.render();
-
-        // Center the procedure declaration block.
-        const metrics = this.workspace.getMetrics();
-        const dx = (metrics.viewWidth / 2) - (this.mutationRoot.width / 2);
-        const dy = (metrics.viewHeight / 2) - (this.mutationRoot.height / 2);
-        this.mutationRoot.moveBy(dx, dy);
     }
     handleCancel () {
         this.props.onRequestClose();
-- 
GitLab