ui/common/context.c

changeset 1169
c69f2941d536
parent 1168
2f9d8af6a499
--- a/ui/common/context.c	Thu Jun 04 19:59:58 2026 +0200
+++ b/ui/common/context.c	Thu Jun 04 20:35:31 2026 +0200
@@ -139,6 +139,10 @@
 }
 
 void uic_context_update_bindings(UiContext *ctx) {
+    int onchange_enabled = ui_onchange_events_is_enabled();
+    int onselection_enabled = ui_selection_events_is_enabled();
+    ui_onchange_events_enable(FALSE);
+    ui_selection_events_enable(FALSE);
     // if a document variable has the same name as a parent variable,
     // move the bindings to the document
     UiContext *var_ctx = ctx->parent;
@@ -167,6 +171,8 @@
             uic_context_update_bindings(subctx);
         }
     }
+    ui_onchange_events_enable(onchange_enabled);
+    ui_selection_events_enable(onselection_enabled);
 }
 
 void uic_context_attach_document(UiContext *ctx, void *document) {
@@ -187,7 +193,10 @@
 }
 
 static void uic_context_unbind_vars(UiContext *ctx) {
+    int onchange_enabled = ui_onchange_events_is_enabled();
+    int onselection_enabled = ui_selection_events_is_enabled();
     ui_onchange_events_enable(FALSE);
+    ui_selection_events_enable(FALSE);
     CxMapIterator mi = cxMapIterator(ctx->vars);
     cx_foreach(CxMapEntry*, entry, mi) {
         //printf("detach %.*s\n", (int)entry->key->len, (char*)entry->key->data);
@@ -210,7 +219,8 @@
         }
     }
     
-    ui_onchange_events_enable(TRUE);
+    ui_onchange_events_enable(onchange_enabled);
+    ui_selection_events_enable(onselection_enabled);
 }
 
 void uic_context_detach_document(UiContext *ctx, void *document) {
@@ -464,6 +474,14 @@
         case UI_VAR_LIST: {         
             UiList *f = from;
             UiList *t = to;
+            // save selection
+            ui_list_selection_free(f->saved_selection);
+            if(f->getselection && f->save_selection) {
+                f->saved_selection = ui_list_get_selection_allocated(f);
+            } else {
+                f->saved_selection = NULL;
+            }
+    
             uic_list_copy(f, t);
             ui_list_update(t);
             if(t->setselection && t->saved_selection) {

mercurial