From 9a9f9fbd6d4726eeb8d56c4e1fc997ee239de1d3 Mon Sep 17 00:00:00 2001
From: Ivica Ico Bukvic <ico@vt.edu>
Date: Fri, 20 Jul 2012 23:27:47 -0400
Subject: [PATCH] fixed regression where arrays did not get moved by tag,
 resulting in a much more inefficient displacement, fixed stray redrawing of
 nlets on multi-gop cut/paste_atmouse (workaround due to limitations of the
 networked model between the gui and the engine, fixed offset bug where object
 got displaced (as in duplicated) when undoing their deletion.

---
 src/g_editor.c | 12 +++++++++++-
 src/g_graph.c  |  9 ++++++---
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/g_editor.c b/src/g_editor.c
index aee3dc621..6588f3dfd 100644
--- a/src/g_editor.c
+++ b/src/g_editor.c
@@ -3335,6 +3335,7 @@ void canvas_mouseup(t_canvas *x,
     /* displace the selection by (dx, dy) pixels */
 static void canvas_displaceselection(t_canvas *x, int dx, int dy)
 {
+	//fprintf(stderr,"canvas_displaceselection %d %d\n", dx, dy);
     t_selection *y;
     int resortin = 0, resortout = 0;
     if (!canvas_undo_already_set_move)
@@ -4295,7 +4296,14 @@ static void canvas_paste_atmouse(t_canvas *x)
 
 	/* find the initial offset--we use leftmost object as our reference */
     for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next) {
+		//fprintf(stderr,"got selection\n");
 		g = (t_glist *)sel->sel_what;
+		if (pd_class(&((t_gobj *)g)->g_pd) == canvas_class && g->gl_isgraph) {
+			// hack: 	if any objects are GOPs redraw them, otherwise we may get stray nlets
+			//			due to networked nature between the gui and the engine, so we select
+			//			it explicitly here once again to prevent that from being a problem
+			gobj_select((t_gobj *)g, x, 1);
+		}
 		t = (t_text *)g;
 		if (!init) {
 			x1 = t->te_xpix;
@@ -4362,6 +4370,8 @@ static void canvas_dopaste(t_canvas *x, t_binbuf *b)
 		offset = 0;
 		glist_noselect(c_selection);
 	}
+	//if we are undoing, offset should be also 0
+	if (we_are_undoing) offset = 0;
 	//else is we are pasting see if we can autopatch
 	else if (canvas_undo_name && !strcmp(canvas_undo_name, "paste")) {
 		canvas_howputnew(x, &connectme, &xpix, &ypix, &indx, &nobj);
@@ -4428,7 +4438,7 @@ static void canvas_dopaste(t_canvas *x, t_binbuf *b)
 	if (!abort_when_pasting_from_external_buffer) {
 	    glist_donewloadbangs(x);
 	} else {
-		error("failed pasting correctly from external buffer, likely due to incomplete text selection (a.k.a. user error). hopefully you saved your work... please get ready to crash...");
+		error("failed pasting correctly from external buffer, likely due to incomplete text selection. hopefully you saved your work... please get ready to crash...");
 	}
 	abort_when_pasting_from_external_buffer = 0;
 }
diff --git a/src/g_graph.c b/src/g_graph.c
index cc88f7ea2..a2bd5d091 100644
--- a/src/g_graph.c
+++ b/src/g_graph.c
@@ -1101,12 +1101,14 @@ static void graph_displace_withtag(t_gobj *z, t_glist *glist, int dx, int dy)
 		// first check for legacy objects that don't offer displacefnwtag and fallback on the old way of doing things
 		t_gobj *g;
 		for (g = x->gl_list; g; g = g->g_next) {
-			if (g && g->g_pd->c_wb->w_displacefnwtag == NULL) {
+			if (g && g->g_pd->c_wb->w_displacefnwtag == NULL && pd_class((t_pd *)g) != garray_class) {
+				//fprintf(stderr,"old way\n");
 				graph_displace(z, glist, dx, dy);
 				return;
 			}
 		}
 		// else we do things the new and more elegant way
+		//fprintf(stderr,"new way\n");
         x->gl_obj.te_xpix += dx;
         x->gl_obj.te_ypix += dy;
         canvas_fixlinesfor(glist_getcanvas(glist), &x->gl_obj);
@@ -1142,12 +1144,13 @@ static void graph_select(t_gobj *z, t_glist *glist, int state)
 */
         	sys_vgui(".x%lx.c itemconfigure %s -fill %s\n",
                  canvas, rtext_gettag(y), 
-                 (state? "$select_color" : "$graph_outline"));
+                 (state? "$select_color" : "$text_color"));
 		}
+
 		t_gobj *g;
 		if (x->gl_list)
 			for (g = x->gl_list; g; g = g->g_next)
-				if (g && g->g_pd->c_wb->w_displacefnwtag != NULL)
+				if (g && (g->g_pd->c_wb->w_displacefnwtag != NULL || pd_class((t_pd *)g) == garray_class))
 					gobj_select(g, x, state);
 		sys_vgui("pdtk_select_all_gop_widgets .x%lx %s %d\n", canvas, rtext_gettag(glist_findrtext(glist, &x->gl_obj)), state);
     }
-- 
GitLab