在Eclipse中是否有CaretListener的替代方法? [英] Is there an alternative to CaretListener in Eclipse?
问题描述
在Eclipse插件中,我需要知道代码编辑器(隐式或显式)中插入符号何时被移动。目前我正在使用CaretListener来实现这一点。
In an Eclipse plugin, I need to find out when the caret is moved in the code editor (either implicitly or explicitly). At the moment I am achieving this with CaretListener.
我只是想知道是否有其他方法来做到这一点?原因是CaretListener只能从3.5版本获得,我认为这是唯一支持旧版本的东西。
I was just wondering if there is an alternative way of doing this? The reason is that CaretListener is only available from version 3.5 and I think that is the only thing holding me back from supporting older versions.
谢谢,
Alan
Thanks, Alan
推荐答案
我确实发现了另外一种在插入符号移动时被通知的方式。通过在TextViewer实例上调用 textViewer.addPostSelectionChangedListener ,您将在插入符移动时收到通知。
I did find another way of being notified when the caret moved. By calling textViewer.addPostSelectionChangedListener on a TextViewer instance, you get notified when the caret moves.
我还使用了这个 answer 从IEditorPart获取TextViewer。
I also used this answer to get a TextViewer from an IEditorPart.
唯一的问题是,这种方法明显比我之前使用caretMoved事件的方式慢。所以,我希望有一种方法可以根据Eclipse的版本来改变行为,因为我不知道我是否乐意在新版本中作出如此妥协的速度。
The only problem is that this method is noticeably slower than the way I was doing it before with the caretMoved event. So, I hope that there is a way that I can change the behaviour depending on the version of Eclipse because I'm not sure if I am happy to make such a compromise on speed in the newer versions.
我希望这有助于其他遇到这个问题的人。
I hope this helps others who come across this question.
Alan
这篇关于在Eclipse中是否有CaretListener的替代方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!