--- a/ui/common/context.c Sat Oct 04 10:59:56 2025 +0200 +++ b/ui/common/context.c Sat Oct 04 12:29:44 2025 +0200 @@ -103,21 +103,19 @@ 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 + // if a document variable has the same name as a parent variable, + // move the bindings to the document UiContext *var_ctx = ctx; while(var_ctx) { - if(var_ctx->vars_unbound && cxMapSize(var_ctx->vars_unbound) > 0) { - CxMapIterator i = cxMapIterator(var_ctx->vars_unbound); - cx_foreach(CxMapEntry*, entry, i) { - printf("attach %s\n", entry->key->data); - UiVar *var = entry->value; - UiVar *docvar = cxMapGet(doc_ctx->vars, *entry->key); - if(docvar) { - // bind var to document var - uic_copy_binding(var, docvar, TRUE); - cxIteratorFlagRemoval(i); - } + CxMapIterator i = cxMapIterator(var_ctx->vars); + cx_foreach(CxMapEntry*, entry, i) { + printf("attach %.*s\n", (int)entry->key->len, entry->key->data); + UiVar *var = entry->value; + UiVar *docvar = cxMapGet(doc_ctx->vars, *entry->key); + if(docvar) { + // bind var to document var + uic_copy_binding(var, docvar, TRUE); + cxIteratorFlagRemoval(i); } } @@ -130,10 +128,10 @@ cx_foreach(CxMapEntry*, entry, mi) { UiVar *var = entry->value; // var->from && var->from_ctx && var->from_ctx != ctx + uic_save_var(var); if(var->from) { - uic_save_var2(var); uic_copy_binding(var, var->from, FALSE); - cxMapPut(var->from->from_ctx->vars_unbound, *entry->key, var->from); + cxMapPut(var->from->from_ctx->vars, *entry->key, var->from); var->from = NULL; } } @@ -200,13 +198,6 @@ } UiVar* uic_create_var(UiContext *ctx, const char *name, UiVarType type) { - if(ctx->vars_unbound) { - UiVar *unbound = cxMapGet(ctx->vars_unbound, name); - if(unbound) { - return unbound; - } - } - UiVar *var = uic_get_var(ctx, name); if(var) { if(var->type == type) { @@ -225,10 +216,7 @@ cxMempoolSetDestructor(var, (cx_destructor_func)uic_unbind_var); - if(!ctx->vars_unbound) { - ctx->vars_unbound = cxHashMapCreate(ctx->allocator, CX_STORE_POINTERS, 16); - } - cxMapPut(ctx->vars_unbound, name, var); + cxMapPut(ctx->vars, name, var); return var; } @@ -279,7 +267,7 @@ } -UiVar* uic_widget_var(UiContext* toplevel, UiContext* current, void* value, const char* varname, UiVarType type) { +UiVar* uic_widget_var(UiContext *toplevel, UiContext *current, void *value, const char *varname, UiVarType type) { if (value) { return uic_create_value_var(current, value); } @@ -384,7 +372,7 @@ ui_setop_enable(FALSE); } -void uic_save_var2(UiVar *var) { +void uic_save_var(UiVar *var) { switch(var->type) { case UI_VAR_SPECIAL: break; case UI_VAR_INTEGER: uic_int_save(var->value); break;