From b0c1fdefe471002fd9758d9a6584f390a575f702 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Sat, 29 Mar 2025 09:34:50 +0100 Subject: [PATCH] fix editor_get_markdown does not get text from the last section sometimes --- application/gtk-text.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/application/gtk-text.c b/application/gtk-text.c index 41156e9..dfd65b0 100644 --- a/application/gtk-text.c +++ b/application/gtk-text.c @@ -728,11 +728,19 @@ cxmutstr editor_get_markdown(UiText *text, const CxAllocator *a) { GtkTextChildAnchor *anchor = NULL; + GtkTextIter end_iter; + gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, -1); + int end_offset = gtk_text_iter_get_offset(&end_iter); + GtkTextIter start; GtkTextIter iter; gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0); start = iter; - while(gtk_text_iter_forward_to_tag_toggle(&iter, NULL)) { + while(gtk_text_iter_get_offset(&iter) < end_offset) { + if(!gtk_text_iter_forward_to_tag_toggle(&iter, NULL)) { + iter = end_iter; + } + if(anchor) { EmbeddedWidget *em = g_object_get_data(G_OBJECT(anchor), "em"); if(em) { @@ -752,6 +760,7 @@ cxmutstr editor_get_markdown(UiText *text, const CxAllocator *a) { } } if(!anchor) { + // we have not checked the anchor at iter anchor = gtk_text_iter_get_child_anchor(&iter); } -- 2.43.5