+static void edit_insert_text_cb(
+ GtkTextBuffer *buffer,
+ const GtkTextIter *location,
+ gchar *text,
+ gint len,
+ NoteEditor *editor)
+{
+ GtkTextIter begin = *location;
+ GtkTextIter end = begin;
+
+ if(!gtk_text_iter_backward_chars(&begin, len)) {
+ return; // should not happen
+ }
+
+ GtkTextIter prev = begin;
+ if(gtk_text_iter_backward_char(&prev)) {
+ // a previous position exists, apply tags from it
+ GSList *tags = gtk_text_iter_get_tags(&prev);
+ while(tags) {
+ GtkTextTag *tag = tags->data;
+ GValue name_value = G_VALUE_INIT;
+ g_object_get_property(G_OBJECT(tag), "name", &name_value);
+ const char *name = g_value_get_string(&name_value);
+ //printf("apply tag: %s\n", name);
+ if(name && name[0] == '_') {
+ // non-paragraph styles start with an underscore
+ // we don't need to apply paragraph styles, the inserted
+ // text will already be inside the paragraph bounds
+
+ // check if the style is temporarily disabled
+ gboolean style_disabled =
+ (editor->disable_bold && !strcmp(name, EDITOR_STYLE_STRONG)) ||
+ (editor->disable_italic && !strcmp(name, EDITOR_STYLE_EMPHASIS)) ||
+ (editor->disable_code && !strcmp(name, EDITOR_STYLE_CODE));
+ if(!style_disabled) {
+ gtk_text_buffer_apply_tag(buffer, tags->data, &begin, &end);
+ }
+ }
+ g_value_unset(&name_value);
+
+ tags = tags->next;
+ }
+ g_slist_free(tags);
+ }
+}
+