diff -r 8e06a446d552 -r 31213068c2ba ui/common/context.c
--- a/ui/common/context.c	Mon Feb 24 22:08:27 2025 +0100
+++ b/ui/common/context.c	Wed Feb 26 17:06:56 2025 +0100
@@ -139,8 +139,8 @@
 
 void uic_context_detach_document2(UiContext *ctx, void *document) {
     // find the document in the documents list
-    ssize_t docIndex = cxListFind(ctx->documents, document);
-    if(docIndex < 0) {
+    size_t docIndex = cxListFind(ctx->documents, document);
+    if(!cxListIndexValid(ctx->documents, docIndex)) {
         return;
     }