cxstring lines[64];
size_t nlines = cx_strsplit(ins_text, "\n", 64, lines);
+ int remove_list_off = -1;
+
int list_depth = 0;
int list_style = 0;
int list_num = 0;
if(nlines > 1) {
// Inserted text contains at least one linebreak
// Check if the current line contains a list
- GtkTextIter prev_line = begin;
+ GtkTextIter prev_line = *location;
if(gtk_text_iter_backward_line(&prev_line)) {
GtkTextChildAnchor *anchor = NULL;
GtkTextChildAnchor *prevAnchor = NULL;
+ int anchor_off = -1;
int end_offset = gtk_text_iter_get_offset(&begin);
// iterate over chars in line and check for anchors
- while(gtk_text_iter_get_offset(&prev_line) < end_offset) {
- if(!gtk_text_iter_forward_to_tag_toggle(&prev_line, NULL)) {
- prev_line = begin;
- }
-
+ int chars_per_line = 0;
+ int off;
+ while((off = gtk_text_iter_get_offset(&prev_line)) < end_offset) {
anchor = gtk_text_iter_get_child_anchor(&prev_line);
if(anchor && anchor != prevAnchor) {
EmbeddedWidget *em = g_object_get_data(G_OBJECT(anchor), "em");
list_style = em->intdata1;
list_num = em->intdata2;
list_depth++;
+ anchor_off = off;
} else if(em->type == EMBEDDED_WIDGET_LIST_INDENT) {
list_depth++;
+ anchor_off = off;
} // else: other type of embedded widget (image, ...)
}
}
prevAnchor = anchor;
+
+ if(!gtk_text_iter_forward_char(&prev_line)) {
+ prev_line = begin;
+ }
+ chars_per_line++;
+ }
+
+ if(chars_per_line == 1) {
+ // empty list element -> inserting a newline terminates the list
+ list_depth = 0;
+ remove_list_off = off;
}
}
}
editor_insert_list_element(editor, &iter, style_name, list_num+i+1);
}
}
+
+ if(remove_list_off > 0) {
+ GtkTextIter iter;
+ gtk_text_buffer_get_iter_at_offset(buffer, &iter, remove_list_off-1);
+ GtkTextIter iter2 = iter;
+ gtk_text_iter_forward_char(&iter2);
+ gtk_text_buffer_delete(buffer, &iter, &iter2);
+ }
}
static gboolean path_is_image_file(cxstring path) {