我如何理解以下含义?

引自这里 :

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); } 

虽然有很多评论,但我仍然不理解其中的逻辑,特别是, 标记滚动条位置之间的关系是什么?

UPDATE

我似乎误导了这个评论:

  /* and place the mark at iter. the mark will stay there after we * insert some text at the end because it has right gravity. */ 

说, scroll标记有重力,而不是重力,是吗?

标记与滚动条的位置无关

它们在该代码中使用标记,因为它便于gtk_text_view_scroll_mark_onscreen()函数,它是计算标记位置的快捷方式,然后将滚动条移动到该位置。

"end"标记是右重力标记,因此当它们将文本添加到缓冲区的末尾时,标记将保留在结尾处。 这样,当他们scroll_mark_onscreen ,垂直和水平滚动条都会移动,以显示最后一行的结尾。

"scroll"标记留下了重力。 当他们将文本添加到缓冲区的末尾时,他们并不关心它的位置,因为他们在添加文本时将它们自己移动到最后一行的开头 。 这样,当他们scroll_mark_onscreen ,只有垂直滚动条移动,以显示最后一行的开头

它们也可能对两个标记都具有正确的重力,因为它们并不关心"scroll"标记的位置。

他们也可以同时为两个标记留下重力,并且只要他们添加文本就手动将"end"标记移动到最后一行的末尾,但他们没有,因为他们可以通过给出自动获得相同的效果"end"标志右重力。

在检查GTK文档后, mark似乎是滚动区域中的某种命名位置,而滚动条的位置是您实际滚动到的缓冲区中的位置。 如果您对HTML更熟悉,那么mark似乎与网页上的锚点略微相同,您可以通过编程方式滚动到该网页。

在滚动函数中,函数gtk_text_view_scroll_mark_onscreen()用于定位滚动条。 这似乎是同步文本位置和滚动条位置的最简单方法。

他们使用两个函数来模拟“显示文本的结尾”(即可能包含水平偏移的东西)和“显示文本的最后一行”(其中水平偏移保持不变)。