[gnome-builder] util: add helper to remove GtkTextTag with minimal damage
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] util: add helper to remove GtkTextTag with minimal damage
- Date: Fri, 22 Apr 2016 07:36:46 +0000 (UTC)
commit 7dd9ceaf54d36650714c5fdb450f0954317b5bf7
Author: Christian Hergert <chergert redhat com>
Date: Fri Apr 22 00:35:06 2016 -0700
util: add helper to remove GtkTextTag with minimal damage
Normally, removing text tags is done with an optimization to just wipe
the index of all items and damage the whole view. However, this causes
lots of drawing during interactive editing (where showing and removing
error squiggles is common).
To work around this, we just do the removal of items manually which
damages far less of the screen real-estate.
libide/util/ide-gtk.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++
libide/util/ide-gtk.h | 5 ++++
2 files changed, 58 insertions(+), 0 deletions(-)
---
diff --git a/libide/util/ide-gtk.c b/libide/util/ide-gtk.c
index 104e554..5674c54 100644
--- a/libide/util/ide-gtk.c
+++ b/libide/util/ide-gtk.c
@@ -324,3 +324,56 @@ ide_widget_find_child_typed (GtkWidget *widget,
return state.ret;
}
+
+/**
+ * ide_gtk_text_buffer_remove_tag:
+ *
+ * Like gtk_text_buffer_remove_tag() but allows specifying that the tags
+ * should be removed one at a time to avoid over-damaging the views
+ * displaying @buffer.
+ */
+void
+ide_gtk_text_buffer_remove_tag (GtkTextBuffer *buffer,
+ GtkTextTag *tag,
+ const GtkTextIter *start,
+ const GtkTextIter *end,
+ gboolean minimal_damage)
+{
+ GtkTextIter tag_begin;
+ GtkTextIter tag_end;
+
+ g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
+ g_return_if_fail (GTK_IS_TEXT_TAG (tag));
+ g_return_if_fail (start != NULL);
+ g_return_if_fail (end != NULL);
+
+ if (!minimal_damage)
+ {
+ gtk_text_buffer_remove_tag (buffer, tag, start, end);
+ return;
+ }
+
+ tag_begin = *start;
+
+ if (!gtk_text_iter_starts_tag (&tag_begin, tag))
+ {
+ if (!gtk_text_iter_forward_to_tag_toggle (&tag_begin, tag))
+ return;
+ }
+
+ tag_end = tag_begin;
+
+ while (gtk_text_iter_compare (&tag_begin, end) < 0)
+ {
+ if (!gtk_text_iter_forward_to_tag_toggle (&tag_end, tag))
+ return;
+
+ gtk_text_iter_forward_char (&tag_end);
+ gtk_text_buffer_remove_tag (buffer, tag, &tag_begin, &tag_end);
+
+ tag_begin = tag_end;
+
+ if (!gtk_text_iter_forward_to_tag_toggle (&tag_begin, tag))
+ return;
+ }
+}
diff --git a/libide/util/ide-gtk.h b/libide/util/ide-gtk.h
index 5f35c33..eaf91af 100644
--- a/libide/util/ide-gtk.h
+++ b/libide/util/ide-gtk.h
@@ -44,6 +44,11 @@ void ide_widget_show_with_fade (GtkWidget *widget);
IdeWorkbench *ide_widget_get_workbench (GtkWidget *widget);
gpointer ide_widget_find_child_typed (GtkWidget *widget,
GType type);
+void ide_gtk_text_buffer_remove_tag (GtkTextBuffer *buffer,
+ GtkTextTag *tag,
+ const GtkTextIter *start,
+ const GtkTextIter *end,
+ gboolean minimal_damage);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]