Index: gtkhtml/ChangeLog
===================================================================
--- gtkhtml/ChangeLog	(revision 8862)
+++ gtkhtml/ChangeLog	(working copy)
@@ -1,3 +1,13 @@
+2008-06-17  Milan Crha  <mcrha@redhat.com>
+
+	** Fix for bug #423395
+
+	* gtkhtml-private.h: (struct _GtkHTMLPrivate): New property.
+	* gtkhtml.h: (gtk_html_set_caret_first_focus_anchor):
+	* gtkhtml.c: (gtk_html_set_caret_first_focus_anchor), (destroy),
+	(focus), (gtk_html_init): New API to let GtkHTML know where
+	to place cursor on the first focus event, based on the anchor name.
+
 2008-06-09  Milan Crha  <mcrha@redhat.com>
 
 	** Fix for bug #533741 (Patch by Vaclav Slavik.)
Index: gtkhtml/gtkhtml-private.h
===================================================================
--- gtkhtml/gtkhtml-private.h	(revision 8862)
+++ gtkhtml/gtkhtml-private.h	(working copy)
@@ -76,6 +76,8 @@ struct _GtkHTMLPrivate {
 	gboolean in_url_test_mode;
 
 	gboolean in_key_binding;
+
+	char *caret_first_focus_anchor;
 };
 
 void  gtk_html_private_calc_scrollbars  (GtkHTML                *html,
Index: gtkhtml/gtkhtml.c
===================================================================
--- gtkhtml/gtkhtml.c	(revision 8862)
+++ gtkhtml/gtkhtml.c	(working copy)
@@ -768,6 +768,7 @@ destroy (GtkObject *object)
 
 		g_free (html->priv->content_type);
 		g_free (html->priv->base_url);
+		g_free (html->priv->caret_first_focus_anchor);
 		g_free (html->priv);
 		html->priv = NULL;
 	}
@@ -2264,6 +2265,7 @@ static gboolean
 focus (GtkWidget *w, GtkDirectionType direction)
 {
 	HTMLEngine *e = GTK_HTML (w)->engine;
+	GtkHTMLPrivate *priv = GTK_HTML (w)->priv;
 
 	if (html_engine_get_editable (e)) {
 		gboolean rv;
@@ -2280,6 +2282,28 @@ focus (GtkWidget *w, GtkDirectionType di
 		e->shift_selection = FALSE;
 	}
 
+	if (!GTK_WIDGET_HAS_FOCUS (w) && e->caret_mode && priv->caret_first_focus_anchor) {
+		int x = 0, y = 0;
+
+		if (html_object_find_anchor (e->clue, priv->caret_first_focus_anchor, &x, &y)) {
+			GtkAdjustment *vadj;
+
+			gtk_widget_grab_focus (w);
+			html_engine_jump_at (e, x, y);
+
+			vadj = GTK_LAYOUT (e->widget)->vadjustment;
+
+			/* scroll to the position on screen if not visible */
+			if (y < vadj->value || y > vadj->value + vadj->page_size)
+				gtk_adjustment_set_value (vadj, y);
+
+			update_primary_selection (GTK_HTML (w));
+			g_signal_emit (GTK_HTML (w), signals [CURSOR_CHANGED], 0);
+
+			return TRUE;
+		}
+	}
+
 	if (((e->focus_object && !(GTK_WIDGET_HAS_FOCUS (w))) || html_engine_focus (e, direction)) && e->focus_object) {
 		gint offset;
 		HTMLObject *obj = html_engine_get_focus_object (e, &offset);
@@ -3270,6 +3294,8 @@ gtk_html_init (GtkHTML* html)
 	html->priv->in_url_test_mode = FALSE;
 	html->priv->in_key_binding = FALSE;
 
+	html->priv->caret_first_focus_anchor = NULL;
+
 	/* IM Context */
 	html->priv->im_context = gtk_im_multicontext_new ();
 	html->priv->need_im_reset = FALSE;
@@ -3913,6 +3939,26 @@ gtk_html_get_caret_mode(const GtkHTML *h
 	return html->engine->caret_mode;
 }
 
+/**
+ * gtk_html_set_caret_first_focus_anchor:
+ * When setting focus to the GtkHTML first time and is in caret mode,
+ * then looks for an anchor of name @param name and tries to set focus
+ * just after it. If NULL, then behaves as before.
+ *
+ * @param html GtkHTML instance.
+ * @param name Name of the anchor to be set the first focus just after it,
+ *             or NULL to not look for the anchor.
+ **/
+void
+gtk_html_set_caret_first_focus_anchor (GtkHTML *html, const char *name)
+{
+	g_return_if_fail (GTK_IS_HTML (html));
+	g_return_if_fail (html->priv != NULL);
+
+	g_free (html->priv->caret_first_focus_anchor);
+	html->priv->caret_first_focus_anchor = g_strdup (name);
+}
+
 void
 gtk_html_set_animate (GtkHTML *html, gboolean animate)
 {
Index: gtkhtml/gtkhtml.h
===================================================================
--- gtkhtml/gtkhtml.h	(revision 8862)
+++ gtkhtml/gtkhtml.h	(working copy)
@@ -208,6 +208,9 @@ void                       gtk_html_set_
 								   gboolean                   caret_mode);
 gboolean                   gtk_html_get_caret_mode                (const GtkHTML             *html);
 
+void			   gtk_html_set_caret_first_focus_anchor  (GtkHTML		     *html,
+								   const char                *name);
+
 /* Animated Images */
 void                       gtk_html_set_animate                   (GtkHTML                   *html,
 								   gboolean                   animate);
