Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在开发一个基于 PyGTK 的 Gedit 插件。我试图弄清楚如何以编程方式告诉光标去哪里。例如,我想让光标自动转到第一个“|”之前 (管道)在当前行。
有什么想法或起点吗?到目前为止,我一直在使用 Gedit API(就在此处),这在很大程度上很有帮助,但没有提及任何有关操纵光标位置的内容。
查看 gedit 插件 API,它看起来像是gedit.Document一个子类,GtkSourceBuffer它本身就是子类GtkTextBuffer,最后一个具有您想要的光标操作 API。特别是,get_insert()并place_cursor(where)给出移动光标的基础知识。对于其他操作(例如,获取当前行),您需要转换为GtkTextIterusing get_iter_at_mark(mark); 光标本质上只是一个特殊的GtkTextMark.
gedit.Document
GtkSourceBuffer
GtkTextBuffer
get_insert()
place_cursor(where)
GtkTextIter
get_iter_at_mark(mark)
GtkTextMark