GtkTextTagTable *tagtable = gtk_text_buffer_get_tag_table(buffer);
NoteEditor *editor = g_object_get_data(G_OBJECT(textview), "editor");
+ // anything that needs to be inserted into the textbuffer must be inserted
+ // after all other styling operations
+ CxList *insert_attachments = cxLinkedListCreateSimple(CX_STORE_POINTERS);
+
CxIterator i = cxListIterator(styles);
cx_foreach(MDDocStyleSection*, sec, i) {
if(sec->length == MDDocStyleSection_IMAGE) {
- Attachment *attachment = note_get_attachment(note, sec->link);
- 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);
- } else {
- // TODO: what do we do in this case?
- }
+ // don't insert attachments now, because it would mess up the indices
+ // insert in reverse order
+ cxListInsert(insert_attachments, 0, sec);
continue;
}
gtk_text_buffer_apply_tag(buffer, linktag, &begin, &end);
}
}
+
+ i = cxListIterator(insert_attachments);
+ cx_foreach(MDDocStyleSection *, sec, i) {
+ Attachment *attachment = note_get_attachment(note, sec->link);
+ 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);
+ } else {
+ // TODO: what do we do in this case?
+ }
+ }
+
+ cxListFree(insert_attachments);
}
/*