How to get mouse and keyboard events and override the default behavior for Eclipse ITextEditor?

I would like to create an Eclipse plugin that emulates the behavior of the vi text editor. This will require a change in the way mouse and keyboard events are processed. So, for example, if the user presses "h" in normal mode, the cursor should move to the left, and not insert the character "h" in the text buffer. I found an old mailing list that describes how to listen to changes in the document and changes in the presentation, but nothing that describes how to capture low-level keyboard and mouse events, so that the default behavior can be overridden. What would be the best way to achieve this?

+3
source share
1 answer

One idea would be for a specific active text editor that you want to capture with low-level widgets StyledTextthat display the actual text, and also accept keyboard input and add a KeyListener to it.

AbstractTextEditor textEditor = ...
ITextViewer viewer = textEditor.getSourceViewer();
StyledText textWidget = viewer.getTextWidget();
textWidget.addKeyListener(...);
+1
source

Source: https://habr.com/ru/post/1788471/


All Articles