]> uap-core.de Git - note.git/commitdiff
fix EmbeddedWidget markdown serialization
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 20 Apr 2025 12:37:33 +0000 (14:37 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 20 Apr 2025 12:37:33 +0000 (14:37 +0200)
application/gtk-text.c

index 56fef7cbe828d6398026ad4bdfb07f52b4454690..2056180e782d3d7b5539caae055a0e1fd30099b0 100644 (file)
@@ -738,9 +738,7 @@ void editor_apply_styles(Resource *note, UIWIDGET textview, UiText *text, CxList
     cx_foreach(MDDocStyleSection*, sec, i) {
         if(sec->length == MDDocStyleSection_IMAGE) {
             Attachment *attachment = note_get_attachment(note, sec->link);
-            if(attachment && attachment->ui->img->value) {
-                GdkPixbuf *pixbuf = attachment->ui->img->value;
-                    
+            if(attachment && attachment->ui->img->value) {  
                 GtkTextIter iter;
                 gtk_text_buffer_get_iter_at_offset(buffer, &iter, sec->pos);
                 editor_insert_image(editor, attachment, &iter);
@@ -829,6 +827,7 @@ cxmutstr editor_get_markdown(UiText *text, const CxAllocator *a) {
     CxMap *prev_tags = cxHashMapCreateSimple(CX_STORE_POINTERS);
     
     GtkTextChildAnchor *anchor = NULL;
+    GtkTextChildAnchor *prevAnchor = NULL;
     
     GtkTextIter end_iter;
     gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, -1);
@@ -843,11 +842,14 @@ cxmutstr editor_get_markdown(UiText *text, const CxAllocator *a) {
             iter = end_iter;
         }
         
-        if(anchor) {
+        // the same anchor is returned at 2 iter positions, so we need to 
+        // check if this anchor was already serialized
+        if(anchor && anchor != prevAnchor) {
             EmbeddedWidget *em = g_object_get_data(G_OBJECT(anchor), "em");
             if(em) {
                 em->serialize(em, &out);
             }
+            prevAnchor = anchor;
             anchor = NULL;
         }