[gtk/issue-3140] Make sure we don't call back into GtkEntryBuffer
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/issue-3140] Make sure we don't call back into GtkEntryBuffer
- Date: Wed, 9 Sep 2020 10:31:38 +0000 (UTC)
commit f4b410daa751aa85997cd530131b81e8d7e63ff7
Author: Emmanuele Bassi <ebassi gnome org>
Date: Wed Sep 9 11:29:16 2020 +0100
Make sure we don't call back into GtkEntryBuffer
After commit 7e77afe94c14365d538c958d23c1e3e074530415 moved the deletion
of text into the signal handler, in order to make undo work, we need to
override the GtkEntryBuffer::deleted-text class closure when subclassing
GtkEntryBuffer, as well as overriding GtkEntryBufferClass.delete_text,
otherwise the default class closure will be invoked, and will try to
delete an empty buffer.
Fixes: #3140
gtk/gtkpasswordentrybuffer.c | 27 +++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtkpasswordentrybuffer.c b/gtk/gtkpasswordentrybuffer.c
index 05844d2fc5..2c97417f26 100644
--- a/gtk/gtkpasswordentrybuffer.c
+++ b/gtk/gtkpasswordentrybuffer.c
@@ -122,6 +122,21 @@ gtk_password_entry_buffer_real_insert_text (GtkEntryBuffer *buffer,
return n_chars;
}
+static void
+gtk_password_entry_buffer_real_deleted_text (GtkEntryBuffer *buffer,
+ guint position,
+ guint n_chars)
+{
+ GtkPasswordEntryBuffer *self = GTK_PASSWORD_ENTRY_BUFFER (buffer);
+
+ gsize start = g_utf8_offset_to_pointer (self->text, position) - self->text;
+ gsize end = g_utf8_offset_to_pointer (self->text, position + n_chars) - self->text;
+
+ memmove (self->text + start, self->text + end, self->text_bytes + 1 - end);
+ self->text_chars -= n_chars;
+ self->text_bytes -= (end - start);
+}
+
static guint
gtk_password_entry_buffer_real_delete_text (GtkEntryBuffer *buffer,
guint position,
@@ -135,16 +150,7 @@ gtk_password_entry_buffer_real_delete_text (GtkEntryBuffer *buffer,
n_chars = self->text_chars - position;
if (n_chars > 0)
- {
- gsize start = g_utf8_offset_to_pointer (self->text, position) - self->text;
- gsize end = g_utf8_offset_to_pointer (self->text, position + n_chars) - self->text;
-
- memmove (self->text + start, self->text + end, self->text_bytes + 1 - end);
- self->text_chars -= n_chars;
- self->text_bytes -= (end - start);
-
- gtk_entry_buffer_emit_deleted_text (buffer, position, n_chars);
- }
+ gtk_entry_buffer_emit_deleted_text (buffer, position, n_chars);
return n_chars;
}
@@ -175,6 +181,7 @@ gtk_password_entry_buffer_class_init (GtkPasswordEntryBufferClass *klass)
buffer_class->get_length = gtk_password_entry_buffer_real_get_length;
buffer_class->insert_text = gtk_password_entry_buffer_real_insert_text;
buffer_class->delete_text = gtk_password_entry_buffer_real_delete_text;
+ buffer_class->deleted_text = gtk_password_entry_buffer_real_deleted_text;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]