merge of 'b9271e416f6d2ebf8812d86ef589b2344294a5f1' next.minor

Mon, 26 Nov 2007 09:49:59 +0000

author
Sadrul Habib Chowdhury <sadrul@pidgin.im>
date
Mon, 26 Nov 2007 09:49:59 +0000
branch
next.minor
changeset 22002
f7ce39d4f36f
parent 21765
b9271e416f6d (diff)
parent 22001
80abe994a8f3 (current diff)
child 22003
904ebe8d6058

merge of 'b9271e416f6d2ebf8812d86ef589b2344294a5f1'
and '80abe994a8f316750921df1cce49a435885f1688'

--- a/pidgin/gtkimhtml.c	Mon Nov 26 09:28:15 2007 +0000
+++ b/pidgin/gtkimhtml.c	Mon Nov 26 09:49:59 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)

mercurial