From 4258567854b10ab61469ca031335becf234b7861 Mon Sep 17 00:00:00 2001
From: Jonathan Wilkes <jon.w.wilkes@gmail.com>
Date: Sun, 16 Oct 2016 00:12:59 -0400
Subject: [PATCH] revert a change to text_setto from
 91cf2a84308245938cb0f3b91294181b2d284d80 that caused a subtle regression when
 a broken object gets retexted.  (It caused the object to be put at the end of
 the glist, which caused the consequent canvas_restoreconnections call to make
 a wire connection to the wrong object)

---
 pd/src/g_text.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/pd/src/g_text.c b/pd/src/g_text.c
index 9aa6a6bd0..9b1ddd210 100644
--- a/pd/src/g_text.c
+++ b/pd/src/g_text.c
@@ -1649,7 +1649,7 @@ static void text_select(t_gobj *z, t_glist *glist, int state)
                              x->te_type != T_TEXT &&
                              glist_istoplevel(glist))
                 {
-                    /* Not sure yet what this is doing... */
+                    /* Not sure yet what this was doing... */
                     //sys_vgui(".x%lx.c itemconfigure %sR -strokewidth 1 "
                     //         "-strokedasharray {} "
                     //         "-fill $pd_colors(box)\n",
@@ -2572,10 +2572,23 @@ void text_setto(t_text *x, t_glist *glist, char *buf, int bufsize, int pos)
             //fprintf(stderr,"setto not canvas\n");
             binbuf_gettext(x->te_binbuf, &c1, &i1);
             binbuf_gettext(b, &c2, &i2);
-            //if the string doesn't match or if the object we entered is invalid
-            //(e.g. we created an object that failed to create but now we have an
-            //abstraction in patch's path named the same as the desired object)
-            if (strcmp(c1, c2) || (pd_class(&x->te_pd) == text_class && x->te_type != T_TEXT))
+            /* It might be nice here to make another attempt at loading
+               broken objects. For example, there may now be an abstraction
+               in the canvas path-- if so, we should create it.
+
+               However, doing this would require more thought-- for example,
+               if the object indeed remains broken we wouldn't want to call
+               canvas_restoreconnections as our broken object would now
+               be at the end of the glist. (I imagine this is what the
+               canvas_apply_restore_original_position call was meant to
+               fix before it was removed.)
+
+               So instead, we only check for new objects if the string
+               has changed. If this function ever gets cleaned up to become
+               more than just a series of nearly-incomprehensible
+               side-effects, perhaps the issue may be revisited.
+            */
+            if (strcmp(c1, c2))
             {
                 //fprintf(stderr,"text_setto calls canvas_undo_add recreate\n");
                 canvas_undo_add(glist_getcanvas(glist), 10, "recreate",
-- 
GitLab