fix UiContext detaching

2 weeks ago

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 23 Feb 2025 17:10:45 +0100 (2 weeks ago)
changeset 474
971dd0f3a117
parent 473
5fde0356b66a
child 475
8e06a446d552

fix UiContext detaching

ui/common/context.c file | annotate | diff | comparison | revisions
--- a/ui/common/context.c	Sun Feb 23 14:55:23 2025 +0100
+++ b/ui/common/context.c	Sun Feb 23 17:10:45 2025 +0100
@@ -92,6 +92,7 @@
     ctx->document = document;
     
     UiContext *doc_ctx = ui_document_context(document);
+    doc_ctx->parent = ctx;
     
     // check if any parent context has an unbound variable with the same name
     // as any document variable
@@ -111,7 +112,7 @@
             }
         }
         
-        var_ctx = ctx->parent;
+        var_ctx = var_ctx->parent;
     }
 }
 
@@ -119,7 +120,7 @@
     CxMapIterator mi = cxMapIterator(ctx->vars);
     cx_foreach(CxMapEntry*, entry, mi) {
         UiVar *var = entry->value;
-        if(var->from && var->from_ctx) {
+        if(var->from && var->from_ctx && var->from_ctx != ctx) {
             uic_save_var2(var);
             uic_copy_binding(var, var->from, FALSE);
             cxMapPut(var->from_ctx->vars_unbound, *entry->key, var->from);
@@ -148,6 +149,7 @@
     
     UiContext *docctx = ui_document_context(document);
     uic_context_unbind_vars(docctx); // unbind all doc/subdoc vars from the parent
+    docctx->parent = NULL;
 }
 
 void uic_context_detach_all(UiContext *ctx) {

mercurial