[gtk+/touch-text-selection] textview: Unset handles when the buffer changes below these
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/touch-text-selection] textview: Unset handles when the buffer changes below these
- Date: Mon, 27 Aug 2012 15:39:36 +0000 (UTC)
commit adce361ec5680895b303945ad65950eea4b9ac31
Author: Carlos Garnacho <carlos lanedo com>
Date: Mon Aug 27 17:18:21 2012 +0200
textview: Unset handles when the buffer changes below these
On the situations where a different buffer is set, or the current
one is clobbered, the handles are unset. More effort could be indeed
done on setting those after the view has revalidated the contents
and the markers have valid coordinates again, although it's a bit of
a corner case.
Fixes the "hypertext" textview demo leaving handles at odd positions
after the buffer changed.
gtk/gtktextview.c | 42 ++++++++++++++++++++++++++++++++++++++----
1 files changed, 38 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index ba43f2f..fc2cc45 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -458,6 +458,8 @@ static void gtk_text_view_target_list_notify (GtkTextBuffer *buffer,
static void gtk_text_view_paste_done_handler (GtkTextBuffer *buffer,
GtkClipboard *clipboard,
gpointer data);
+static void gtk_text_view_buffer_changed_handler (GtkTextBuffer *buffer,
+ gpointer data);
static void gtk_text_view_get_virtual_cursor_pos (GtkTextView *text_view,
GtkTextIter *cursor,
gint *x,
@@ -507,6 +509,8 @@ static void gtk_text_view_handle_dragged (GtkTextHandle *handle,
gint x,
gint y,
GtkTextView *text_view);
+static void _gtk_text_view_update_handles (GtkTextView *text_view,
+ GtkTextHandleMode mode);
/* FIXME probably need the focus methods. */
@@ -1575,6 +1579,9 @@ gtk_text_view_set_buffer (GtkTextView *text_view,
g_signal_handlers_disconnect_by_func (priv->buffer,
gtk_text_view_paste_done_handler,
text_view);
+ g_signal_handlers_disconnect_by_func (priv->buffer,
+ gtk_text_view_buffer_changed_handler,
+ text_view);
if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
{
@@ -1624,6 +1631,9 @@ gtk_text_view_set_buffer (GtkTextView *text_view,
g_signal_connect (priv->buffer, "paste-done",
G_CALLBACK (gtk_text_view_paste_done_handler),
text_view);
+ g_signal_connect (priv->buffer, "changed",
+ G_CALLBACK (gtk_text_view_buffer_changed_handler),
+ text_view);
gtk_text_view_target_list_notify (priv->buffer, NULL, text_view);
@@ -1633,6 +1643,8 @@ gtk_text_view_set_buffer (GtkTextView *text_view,
GDK_SELECTION_PRIMARY);
gtk_text_buffer_add_selection_clipboard (priv->buffer, clipboard);
}
+
+ _gtk_text_view_update_handles (text_view, GTK_TEXT_HANDLE_MODE_NONE);
}
_gtk_text_view_accessible_set_buffer (text_view, old_buffer);
@@ -4563,7 +4575,6 @@ _gtk_text_view_update_handles (GtkTextView *text_view,
GtkTextIter cursor, bound, min, max;
GtkTextBuffer *buffer;
- _gtk_text_handle_set_mode (priv->text_handle, mode);
buffer = get_buffer (text_view);
gtk_text_buffer_get_iter_at_mark (buffer, &cursor,
@@ -4571,6 +4582,15 @@ _gtk_text_view_update_handles (GtkTextView *text_view,
gtk_text_buffer_get_iter_at_mark (buffer, &bound,
gtk_text_buffer_get_selection_bound (buffer));
+ if (mode == GTK_TEXT_HANDLE_MODE_SELECTION &&
+ gtk_text_iter_compare (&cursor, &bound) == 0)
+ {
+ mode = (priv->editable) ? GTK_TEXT_HANDLE_MODE_CURSOR :
+ GTK_TEXT_HANDLE_MODE_NONE;
+ }
+
+ _gtk_text_handle_set_mode (priv->text_handle, mode);
+
if (gtk_text_iter_compare (&cursor, &bound) >= 0)
{
min = bound;
@@ -4582,10 +4602,9 @@ _gtk_text_view_update_handles (GtkTextView *text_view,
max = bound;
}
-
if (mode != GTK_TEXT_HANDLE_MODE_NONE)
_gtk_text_view_set_handle_position (text_view, &max,
- GTK_TEXT_HANDLE_POSITION_SELECTION_END);
+ GTK_TEXT_HANDLE_POSITION_SELECTION_END);
if (mode == GTK_TEXT_HANDLE_MODE_SELECTION)
_gtk_text_view_set_handle_position (text_view, &min,
@@ -6319,6 +6338,17 @@ gtk_text_view_paste_done_handler (GtkTextBuffer *buffer,
}
static void
+gtk_text_view_buffer_changed_handler (GtkTextBuffer *buffer,
+ gpointer data)
+{
+ GtkTextView *text_view = data;
+ GtkTextViewPrivate *priv;
+
+ priv = text_view->priv;
+ _gtk_text_view_update_handles (text_view, GTK_TEXT_HANDLE_MODE_NONE);
+}
+
+static void
gtk_text_view_toggle_overwrite (GtkTextView *text_view)
{
GtkTextViewPrivate *priv = text_view->priv;
@@ -8163,7 +8193,11 @@ gtk_text_view_mark_set_handler (GtkTextBuffer *buffer,
}
if (need_reset)
- gtk_text_view_reset_im_context (text_view);
+ {
+ gtk_text_view_reset_im_context (text_view);
+ _gtk_text_view_update_handles (text_view,
+ _gtk_text_handle_get_mode (text_view->priv->text_handle));
+ }
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]