在 TextView 中右键单击移动光标?
目前,当用户在 TextView 中单击鼠标右键时,会弹出一个弹出菜单,但光标实际上不会将位置更改为右键单击的位置,而只是保留光标。对于试图实现拼写检查菜单的我来说,这并不好,因为我必须先单击然后右键单击才能将光标置于正确的位置。所以,我的问题是是否有任何方法可以以某种方式修改这种行为,以便它实际上以某种方式做到这一点?
At the moment, when one right clicks in a TextView, a popup menu is brought up, but the cursor doesn't actually change position to where one is right clicking, it just leaves the cursor alone. For me, whom is trying to implement a spell checking menu, this isn't good since I have to click THEN right click in order to get the cursor in the right spot. So, my question is if there is any way to modify this behavior somehow so that it actually does this somehow?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我偶然发现了 gtk.TextView.get_iter_at_location,这让我找到了 gtk.TextView.get_pointer 和 gtk.TextView.window_to_buffer_coords。基本上,为了让它工作,我这样做了:
基本上,它获取指针的位置(相对于窗口),将其转换为缓冲区坐标(我发现 gtk.TEXT_WINDOW_TEXT 给出与 gtk.TEXT_WINDOW_WIDGET 相同的坐标,但我认为我谨慎起见,请使用小部件的窗口),然后在该位置获取迭代器。效果非常好。
Well, I stumbled across gtk.TextView.get_iter_at_location, which lead me to gtk.TextView.get_pointer and gtk.TextView.window_to_buffer_coords. Basically, to get this working, I did this:
Basically, it gets the pointer's position (relative to the window), transforms it to buffer coordinates (I find that gtk.TEXT_WINDOW_TEXT gives the same coordinates as gtk.TEXT_WINDOW_WIDGET, but I thought I'd err on the side of caution and use the widget's window), and then gets an iter at that location. Works wonderfully.