How to receive mouse and keyboard events and override default behaviour for Eclipse ITextEditor?
I'd like to create an Eclipse plugin that emulates the behaviour of the vi text editor. This would require changing the way mouse and keyboard events are handled. So, for example if the user presses "h" while in Normal Mode, the cursor should move left, rather than inserting the "h" character into the text buffer. I've found an old mailing list post that describes how to listen to changes in the document, and changes in the presentation, but nothing that descr开发者_开发技巧ibes how to intercept low-level keyboard and mouse events, such that the default behaviour can be overridden. What would be the best way to accomplish this?
One idea would be for a particular active text editor you would want to grab the low-level StyledText
widget that is rendering the actual text and also accepting keyboard input and add a KeyListener there.
AbstractTextEditor textEditor = ...
ITextViewer viewer = textEditor.getSourceViewer();
StyledText textWidget = viewer.getTextWidget();
textWidget.addKeyListener(...);
精彩评论