Index: src/gtkhtml.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/gtkhtml.c,v
retrieving revision 1.573
diff -u -r1.573 gtkhtml.c
--- src/gtkhtml.c	22 Jul 2004 17:58:55 -0000	1.573
+++ src/gtkhtml.c	6 Aug 2004 10:59:57 -0000
@@ -2998,6 +2998,18 @@
 	gboolean state = html->priv->im_block_reset;
 	gint pos;
 
+        if (html->priv->im_pre_len > 0) {
+                D_IM (printf ("IM delete last preedit %d + %d\n", html->priv->im_pre_pos, html->priv->im_pre_len);)
+                                                                                
+                html_undo_freeze(html->engine->undo);
+                html_cursor_jump_to_position_no_spell (html->engine->cursor, html->engine, html->priv->im_pre_pos);
+                html_engine_set_mark (html->engine);
+                html_cursor_jump_to_position_no_spell (html->engine->cursor, html->engine, html->priv->im_pre_pos + html->priv->im_pre_len);
+                html_engine_delete (html->engine);
+                html->priv->im_pre_len = 0;
+                html_undo_unfreeze(html->engine->undo);
+        }
+
 	pos = html->engine->cursor->position;
 	if (html->engine->mark && html->engine->mark->position > pos)
 		pos = html->engine->mark->position;
@@ -3044,6 +3056,8 @@
 	initial_position = html->engine->cursor->position;
 	D_IM (printf ("IM initial position %d\n", initial_position);)
 
+	html_undo_freeze(html->engine->undo);
+
 	if (html->priv->im_pre_len > 0) {
 		D_IM (printf ("IM delete last preedit %d + %d\n", html->priv->im_pre_pos, html->priv->im_pre_len);)
 		
@@ -3087,6 +3101,8 @@
 		html_engine_thaw_idle_flush (html->engine);
 	/* FIXME gtk_im_context_set_cursor_location (im_context, &area); */
 	html->priv->im_block_reset = state;
+
+	html_undo_unfreeze(html->engine->undo);
 
 	D_IM (printf ("IM preedit changed cb [end] cursor %d(%p) mark %d(%p) active: %d\n",
 		      html->engine->cursor ? html->engine->cursor->position : 0, html->engine->cursor,
Index: src/htmlundo.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/htmlundo.c,v
retrieving revision 1.17
diff -u -r1.17 htmlundo.c
--- src/htmlundo.c	16 Jul 2002 22:16:59 -0000	1.17
+++ src/htmlundo.c	6 Aug 2004 10:59:57 -0000
@@ -42,6 +42,8 @@
 	guint     level;
 	guint     in_redo;
 	gint      step_counter;
+
+	gboolean freeze; /* Undo freeze flag for im context */
 };
 
 #ifdef UNDO_DEBUG
@@ -150,6 +152,9 @@
 	g_return_if_fail (undo != NULL);
 	g_return_if_fail (engine != NULL);
 
+	if( undo->freeze )
+		return;
+
 	if (undo->undo.size > 0) {
 #ifdef UNDO_DEBUG
 		if (!undo->level) {
@@ -177,6 +182,9 @@
 	g_return_if_fail (undo != NULL);
 	g_return_if_fail (engine != NULL);
 
+	if( undo->freeze )
+		return;
+
 	if (undo->redo.size > 0) {
 #ifdef UNDO_DEBUG
 		if (!undo->level) {
@@ -209,6 +217,9 @@
 	if (undo->redo.stack == NULL)
 		return;
 
+	if( undo->freeze )
+		return;
+
 	destroy_action_list (undo->redo.stack);
 
 	undo->redo.stack = NULL;
@@ -221,6 +232,9 @@
 	g_return_if_fail (undo != NULL);
 	g_return_if_fail (action != NULL);
 
+	if( undo->freeze )
+		return;
+
 	if (undo->level == 0) {
 		if (undo->in_redo == 0 && undo->redo.size > 0)
 			add_used_and_redo_to_undo (undo);
@@ -261,6 +275,9 @@
 	g_return_if_fail (undo != NULL);
 	g_return_if_fail (action != NULL);
 
+	if( undo->freeze )
+		return;
+
 	undo->redo.stack = g_list_prepend (undo->redo.stack, action);
 	undo->redo.size ++;
 }
@@ -268,10 +285,25 @@
 void
 html_undo_add_action  (HTMLUndo *undo, HTMLUndoAction *action, HTMLUndoDirection dir)
 {
+	if( undo->freeze )
+		return;
+
 	if (dir == HTML_UNDO_UNDO)
 		html_undo_add_undo_action (undo, action);
 	else
 		html_undo_add_redo_action (undo, action);
+}
+
+void
+html_undo_freeze (HTMLUndo        *undo)
+{
+	undo->freeze = TRUE;
+}
+
+void
+html_undo_unfreeze (HTMLUndo        *undo)
+{
+	undo->freeze = FALSE;
 }
 
 /*
Index: src/htmlundo.h
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/htmlundo.h,v
retrieving revision 1.8
diff -u -r1.8 htmlundo.h
--- src/htmlundo.h	16 Jul 2002 22:16:59 -0000	1.8
+++ src/htmlundo.h	6 Aug 2004 10:59:57 -0000
@@ -54,6 +54,8 @@
 				      const gchar       *redo_description);
 void      html_undo_level_end        (HTMLUndo          *undo);
 gint      html_undo_get_step_count   (HTMLUndo          *undo);
+void      html_undo_freeze           (HTMLUndo        *undo);
+void      html_undo_unfreeze         (HTMLUndo        *undo);
 /*
  *  Undo Data
  */
