@@ -302,9 +302,25 @@ def build_update_commands(self, index, added_controls, commands, isolated=False)
302302 ids = []
303303 for h in previous_ints [a1 :a2 ]:
304304 ctrl = hashes [h ]
305+ # check if re-added control is being deleted
306+ # which means it's a replace
307+ i = 0
308+ replaced = False
309+ while i < len (commands ):
310+ cmd = commands [i ]
311+ if cmd .name == "add" and any (
312+ c for c in cmd .commands if c .attrs ["id" ] == ctrl .__uid
313+ ):
314+ # insert delete command before add
315+ commands .insert (i , Command (0 , "remove" , [ctrl .__uid ]))
316+ replaced = True
317+ break
318+ i += 1
305319 self ._remove_control_recursively (index , ctrl )
306- ids .append (ctrl .__uid )
307- commands .append (Command (0 , "remove" , ids ))
320+ if not replaced :
321+ ids .append (ctrl .__uid )
322+ if len (ids ) > 0 :
323+ commands .append (Command (0 , "remove" , ids ))
308324 elif tag == "equal" :
309325 # unchanged control
310326 for h in previous_ints [a1 :a2 ]:
@@ -428,7 +444,9 @@ def _build_command(self, update=False):
428444 self .__attrs [attrName ] = (val , False )
429445
430446 id = self .__attrs .get ("id" )
431- if not update and id is not None :
447+ if not update and self .__uid is not None :
448+ command .attrs ["id" ] = self .__uid
449+ elif not update and id is not None :
432450 command .attrs ["id" ] = id
433451 elif update and len (command .attrs ) > 0 :
434452 assert self .__uid is not None
0 commit comments