[gtk/wip/exalm/textview-selection: 3/4] textview: Invalidate selection when its style changes
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/exalm/textview-selection: 3/4] textview: Invalidate selection when its style changes
- Date: Mon, 3 May 2021 17:08:36 +0000 (UTC)
commit 9aca7f0cb85b4d172680adfe7a407ab15f04d5bc
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Mon May 3 21:40:37 2021 +0500
textview: Invalidate selection when its style changes
gtk/gtktextlayout.c | 14 ++++++++++++++
gtk/gtktextlayoutprivate.h | 1 +
gtk/gtktextview.c | 15 +++++++++++++++
3 files changed, 30 insertions(+)
---
diff --git a/gtk/gtktextlayout.c b/gtk/gtktextlayout.c
index c746752be5..aad63f6333 100644
--- a/gtk/gtktextlayout.c
+++ b/gtk/gtktextlayout.c
@@ -833,6 +833,20 @@ gtk_text_layout_invalidate_cursors (GtkTextLayout *layout,
gtk_text_layout_invalidated (layout);
}
+void
+gtk_text_layout_invalidate_selection (GtkTextLayout *layout)
+{
+ GtkTextIter selection_start, selection_end;
+
+ g_return_if_fail (GTK_IS_TEXT_LAYOUT (layout));
+
+ if (layout->buffer &&
+ gtk_text_buffer_get_selection_bounds (layout->buffer,
+ &selection_start,
+ &selection_end))
+ gtk_text_layout_invalidate (layout, &selection_start, &selection_end);
+}
+
void
gtk_text_layout_free_line_data (GtkTextLayout *layout,
GtkTextLine *line,
diff --git a/gtk/gtktextlayoutprivate.h b/gtk/gtktextlayoutprivate.h
index 66676c7e7a..480d1ada62 100644
--- a/gtk/gtktextlayoutprivate.h
+++ b/gtk/gtktextlayoutprivate.h
@@ -287,6 +287,7 @@ void gtk_text_layout_invalidate (GtkTextLayout *layout,
void gtk_text_layout_invalidate_cursors(GtkTextLayout *layout,
const GtkTextIter *start,
const GtkTextIter *end);
+void gtk_text_layout_invalidate_selection (GtkTextLayout *layout);
void gtk_text_layout_free_line_data (GtkTextLayout *layout,
GtkTextLine *line,
GtkTextLineData *line_data);
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 33c40d3555..fd62f3bba1 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -1917,6 +1917,20 @@ _gtk_text_view_ensure_text_handles (GtkTextView *text_view)
}
}
+static void
+selection_node_style_changed_cb (GtkCssNode *node,
+ GtkCssStyleChange *change,
+ GtkWidget *widget)
+{
+ GtkTextView *text_view = GTK_TEXT_VIEW (widget);
+ GtkTextViewPrivate *priv = text_view->priv;
+
+ if (!priv->layout)
+ return;
+
+ gtk_text_layout_invalidate_selection (priv->layout);
+}
+
static void
gtk_text_view_init (GtkTextView *text_view)
{
@@ -2030,6 +2044,7 @@ gtk_text_view_init (GtkTextView *text_view)
gtk_css_node_set_state (priv->selection_node,
gtk_css_node_get_state (priv->text_window->css_node) &
~GTK_STATE_FLAG_DROP_ACTIVE);
gtk_css_node_set_visible (priv->selection_node, FALSE);
+ g_signal_connect_object (priv->selection_node, "style-changed", G_CALLBACK
(selection_node_style_changed_cb), widget, 0);
g_object_unref (priv->selection_node);
gtk_widget_action_set_enabled (GTK_WIDGET (text_view), "text.can-redo", FALSE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]