+static int get_prev_list(GtkTextBuffer *buffer, const GtkTextIter *iter, int *depth, int *style, int *num, int *remove_offset) {
+ int list_depth = 0;
+ int list_style = 0;
+ int list_num = 0;
+ int remove_list_off = -1;
+
+ GtkTextIter iter2 = *iter;
+ GtkTextChildAnchor *anchor = NULL;
+ GtkTextChildAnchor *prevAnchor = NULL;
+ int off = 0;
+ // iterate over chars in line and check for anchors
+ int chars_per_line = 0;
+ while(gtk_text_iter_backward_char(&iter2)) {
+ if(gtk_text_iter_get_char(&iter2) == '\n') {
+ break;
+ }
+ off = gtk_text_iter_get_offset(&iter2);
+
+ anchor = gtk_text_iter_get_child_anchor(&iter2);
+ if(anchor && anchor != prevAnchor) {
+ EmbeddedWidget *em = g_object_get_data(G_OBJECT(anchor), "em");
+ if(em) {
+ if(em->type == EMBEDDED_WIDGET_LIST) {
+ list_style = em->intdata1;
+ list_num = em->intdata2;
+ list_depth++;
+ } else if(em->type == EMBEDDED_WIDGET_LIST_INDENT) {
+ list_depth++;
+ } // else: other type of embedded widget (image, ...)
+ }
+ }
+ prevAnchor = anchor;
+
+ chars_per_line++;
+ }
+
+ if(chars_per_line == 1) {
+ // empty list element -> inserting a newline terminates the list
+ list_depth = 0;
+ *remove_offset = off + 1;
+ }
+
+ if(list_depth > 0) {
+ *depth = list_depth;
+ *style = list_style;
+ *num = list_num;
+ *remove_offset = -1;
+ return 1;
+ }
+ return 0;
+}
+