Commit 11479d3a authored by Michael Natterer's avatar Michael Natterer 😴
Browse files

app: use the tags left of the cursor when inserting

and make sure the style editor's buttons are correct at the beginning
and end of spans (take the tags toggled on/off at these positions into
account).
parent b040220e
......@@ -279,9 +279,32 @@ void
gimp_text_buffer_insert (GimpTextBuffer *buffer,
const gchar *text)
{
GtkTextIter iter, start;
gint start_offset;
GSList *tags_off;
GSList *list;
g_return_if_fail (GIMP_IS_TEXT_BUFFER (buffer));
gtk_text_buffer_insert_at_cursor (GTK_TEXT_BUFFER (buffer), text, -1);
gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (buffer), &iter,
gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (buffer)));
start_offset = gtk_text_iter_get_offset (&iter);
tags_off = gtk_text_iter_get_toggled_tags (&iter, FALSE);
gtk_text_buffer_insert (GTK_TEXT_BUFFER (buffer), &iter, text, -1);
gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (buffer), &start,
start_offset);
for (list = tags_off; list; list = g_slist_next (list))
{
gtk_text_buffer_apply_tag (GTK_TEXT_BUFFER (buffer), list->data,
&start, &iter);
}
g_slist_free (tags_off);
}
gint
......
......@@ -321,6 +321,8 @@ typedef struct
{
GimpTextStyleEditor *editor;
GSList *tags;
GSList *tags_on;
GSList *tags_off;
GtkTextIter iter;
gboolean any_active;
} UpdateTogglesData;
......@@ -358,7 +360,9 @@ gimp_text_style_editor_update_cursor (GtkTextTag *tag,
data->editor);
gtk_toggle_button_set_active (toggle,
g_slist_find (data->tags, tag) != NULL);
(g_slist_find (data->tags, tag) &&
! g_slist_find (data->tags_on, tag)) ||
g_slist_find (data->tags_off, tag));
g_signal_handlers_unblock_by_func (toggle,
gimp_text_style_editor_tag_toggled,
......@@ -411,13 +415,17 @@ gimp_text_style_editor_mark_set (GtkTextBuffer *buffer,
gtk_text_buffer_get_iter_at_mark (buffer, &cursor,
gtk_text_buffer_get_insert (buffer));
data.editor = editor;
data.tags = gtk_text_iter_get_tags (&cursor);
data.editor = editor;
data.tags = gtk_text_iter_get_tags (&cursor);
data.tags_on = gtk_text_iter_get_toggled_tags (&cursor, TRUE);
data.tags_off = gtk_text_iter_get_toggled_tags (&cursor, FALSE);
g_hash_table_foreach (editor->tag_to_toggle_hash,
(GHFunc) gimp_text_style_editor_update_cursor,
&data);
g_slist_free (data.tags);
g_slist_free (data.tags_on);
g_slist_free (data.tags_off);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment