]> uap-core.de Git - note.git/commitdiff
fix switching note could erase a note title/content
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 4 Mar 2025 14:16:43 +0000 (15:16 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 4 Mar 2025 14:16:43 +0000 (15:16 +0100)
application/note.c
application/notebook.c

index 09a9053c0f247415273c0b39eed8698c881d0006..6d8da32e8cab05f0414e9f7bba6296d5673fad5f 100644 (file)
@@ -76,19 +76,24 @@ void note_load_content(UiObject *obj, NotebookModel *notebook, Note *note) {
 
 void note_save(UiObject *obj, NotebookModel *notebook, Note *note) {
     NoteModel *m = note->model;
-    printf("title obj: %s\n", m->title->obj);
     
     char *title = ui_get(m->title);
-    printf("title: %s\n", title);
     char *content = ui_get(m->text);
     const CxAllocator *a = notebook->current_notes_pool->allocator;
     
     cxFree(a, note->title);
     note->title = cx_strdup_a(a, cx_str(title)).ptr;
     
+    cxFree(a, note->name);
+    note->name = cx_strdup_a(a, cx_str(title)).ptr;
+    
     cxFree(a, note->content.ptr);
     note->content = cx_strdup_a(a, cx_str(content));
     
+    if(strlen(title) == 0) {
+        printf("break\n");
+    }
+    
     if(note->note_id == 0) {
         // new note
         note_store_new_note_async(obj, note, NULL, NULL);
index 8156d0bce93f950fdef94564258f294ba502d8cc..698b62a751dfe695839c54e58db44a641a0e383b 100644 (file)
@@ -76,6 +76,7 @@ void notebookmodel_attach(MainWindow *window, NotebookModel *model) {
 
 void notebookmodel_detach(NotebookModel *model) {
     if(model->current_note && model->current_note->model->modified) {
+        //notebookmodel_detach_current_note(model);
         note_save(model->window->obj, model, model->current_note);
     }
     
@@ -124,7 +125,14 @@ void notebookmodel_attach_note(NotebookModel *model, Note *note) {
         notemodel_set_note(notemodel, note);
     }
     
-    notebookmodel_detach_current_note(model);
+    if(model->current_note == note) {
+        // workaround, see top comment
+        ui_detach_document2(model->ctx, model->current_note->model);
+        model->current_note = NULL;
+    } else{
+        notebookmodel_detach_current_note(model);
+    }
+    
     ui_attach_document(model->ctx, note->model);
     // TODO: this is only a workaround and should be removed when
     //       sub-document groups are supported