GTK SourceView 滚动标记不工作
GTK SourceView scroll to mark not working
我正在尝试用文本填充 SourceView 的缓冲区,然后滚动以使特定行可见,如下所示:
lines = '....'.split('\n')
line_number = 76 # For instance, assuming lines has at least this many lines
buffer = view.get_buffer()
for line in lines:
buffer.insert(end_iter, line + '\n')
iter = buffer.get_iter_at_line()
mark = buffer.get_mark('insert')
buffer.move_mark(mark, iter)
mark = buffer.get_mark('selection_bound')
buffer.move_mark(mark, iter)
view.scroll_to_mark(mark, 0.3, True, 0, 0.5)
这将滚动到缓冲区中或多或少的随机位置。我在这里做错了什么吗?或者这根本行不通?
你是对的,scroll_to_iter
取决于空闲重新计算。就此而言,scroll_to_mark
也是如此。这对我有用:
from gi.repository import GLib
#........ code here
GLib.idle_add(view.scroll_to_mark, mark, 0.1, True, 0.0, 0.5)
我正在尝试用文本填充 SourceView 的缓冲区,然后滚动以使特定行可见,如下所示:
lines = '....'.split('\n')
line_number = 76 # For instance, assuming lines has at least this many lines
buffer = view.get_buffer()
for line in lines:
buffer.insert(end_iter, line + '\n')
iter = buffer.get_iter_at_line()
mark = buffer.get_mark('insert')
buffer.move_mark(mark, iter)
mark = buffer.get_mark('selection_bound')
buffer.move_mark(mark, iter)
view.scroll_to_mark(mark, 0.3, True, 0, 0.5)
这将滚动到缓冲区中或多或少的随机位置。我在这里做错了什么吗?或者这根本行不通?
你是对的,scroll_to_iter
取决于空闲重新计算。就此而言,scroll_to_mark
也是如此。这对我有用:
from gi.repository import GLib
#........ code here
GLib.idle_add(view.scroll_to_mark, mark, 0.1, True, 0.0, 0.5)