Mercurial > pidgin.yaz
changeset 21648:3aa34d20d798
Patch from 'goutnet': Pressing backspace on a smiley will replace the smiley
with its text. Pressing backspace again will behave as it would for normal text.
References #3286.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Mon, 26 Nov 2007 09:49:27 +0000 |
parents | d0ea3a86add5 |
children | 419c93864e6b 28c63fdcda73 |
files | pidgin/gtkimhtml.c |
diffstat | 1 files changed, 36 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/pidgin/gtkimhtml.c Mon Nov 26 08:12:40 2007 +0000 +++ b/pidgin/gtkimhtml.c Mon Nov 26 09:49:27 2007 +0000 @@ -1097,6 +1097,38 @@ g_free(text); } + +static void smart_backspace_cb(GtkIMHtml *imhtml, gpointer blah) +{ + GtkTextIter iter; + GtkTextChildAnchor* anchor; + char * text; + gint offset; + + if (!imhtml->editable) + return; + + gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, gtk_text_buffer_get_insert(imhtml->text_buffer)); + + /* Get the character before the insertion point */ + offset = gtk_text_iter_get_offset(&iter); + if (offset <= 0) + return; + + gtk_text_iter_backward_char(&iter); + anchor = gtk_text_iter_get_child_anchor(&iter); + + if (!anchor) + return; /* No smiley here */ + + text = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_plaintext"); + if (!text) + return; + + /* ok, then we need to insert the image buffer text before the anchor */ + gtk_text_buffer_insert(imhtml->text_buffer, &iter, text, -1); +} + static void paste_clipboard_cb(GtkIMHtml *imhtml, gpointer blah) { #ifdef _WIN32 @@ -4052,8 +4084,11 @@ imhtml->format_functions = GTK_IMHTML_ALL; if (editable) + { g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set", - G_CALLBACK(mark_set_cb), imhtml); + G_CALLBACK(mark_set_cb), imhtml); + g_signal_connect(G_OBJECT(imhtml), "backspace", G_CALLBACK(smart_backspace_cb), NULL); + } } void gtk_imhtml_set_whole_buffer_formatting_only(GtkIMHtml *imhtml, gboolean wbfo)