From: Olaf Wintermann Date: Tue, 4 Mar 2025 14:16:43 +0000 (+0100) Subject: fix switching note could erase a note title/content X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=70067a3a57810b4be7b044995383bcaffaf3feaa;p=note.git fix switching note could erase a note title/content --- diff --git a/application/note.c b/application/note.c index 09a9053..6d8da32 100644 --- a/application/note.c +++ b/application/note.c @@ -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); diff --git a/application/notebook.c b/application/notebook.c index 8156d0b..698b62a 100644 --- a/application/notebook.c +++ b/application/notebook.c @@ -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