+void vadj_changed (GtkAdjustment *adj,
+ ModestMsgEditWindow *window)
+{
+ ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+
+ GdkRectangle rectangle, cursor_rectangle;
+ GtkTextIter position;
+ gboolean visible;
+ gint cursor_bottom;
+
+ /* We detect if cursor is visible using the full height, not only the center. This
+ seems to work */
+ gtk_text_view_get_visible_rect (GTK_TEXT_VIEW (priv->msg_body), &rectangle);
+ gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (priv->text_buffer),
+ &position,
+ gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (priv->text_buffer)));
+ gtk_text_view_get_iter_location (GTK_TEXT_VIEW (priv->msg_body), &position, &cursor_rectangle);
+
+ cursor_bottom = (cursor_rectangle.y + cursor_rectangle.height);
+ visible = (cursor_rectangle.y >= rectangle.y) && (cursor_bottom < (rectangle.y + rectangle.height));
+
+ if (gtk_widget_is_focus (priv->msg_body) &&
+ !visible) {
+ if (priv->last_vadj_upper != adj->upper) {
+ GtkTextMark *insert;
+
+ insert = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (priv->text_buffer));
+ gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (priv->msg_body),
+ insert, 0.1, FALSE, 0.0, 0.0);
+ }
+ }
+ priv->last_vadj_upper = adj->upper;
+}
+