Quoted from here:
if (to_end)
{
/* If we want to scroll to the end, including horizontal scrolling,
* then we just create a mark with right gravity at the end of the
* buffer. It will stay at the end unless explicitely moved with
* gtk_text_buffer_move_mark.
*/
gtk_text_buffer_create_mark (buffer, "end", &iter, FALSE);
/* Add scrolling timeout. */
return g_timeout_add (50, (GSourceFunc) scroll_to_end, textview);
}
else
{
/* If we want to scroll to the bottom, but not scroll horizontally,
* then an end mark won't do the job. Just create a mark so we can
* use it with gtk_text_view_scroll_mark_onscreen, we'll position it
* explicitely when needed. Use left gravity so the mark stays where
* we put it after inserting new text.
*/
gtk_text_buffer_create_mark (buffer, "scroll", &iter, TRUE);
/* Add scrolling timeout. */
return g_timeout_add (100, (GSourceFunc) scroll_to_bottom, textview);
}
Though there are quite a few lines of comments, I still don't understand the logic in it,especially, what's the relation between an mark and the position of scroll bar?
UPDATE
It seems that I'm mislead by this comment:
/* and place the mark at iter. the mark will stay there after we
* insert some text at the end because it has right gravity.
*/
Say, the scroll
mark has left gravity,not right gravity,is that right?