I have a JFace SourceViewer that I’m modifying and I want to capture when a user presses the ENTER key inside of it, execute some code, and then cancel further execution of the ENTER event. In other words, I don’t want a carriage return in the SourceViewer text.
I have a KeyListener and a TraverseListener set up and all of them are getting fired correctly, but when I set evt.doit = false the carriage return still shows up in the source viewer.
If I do the same thing in a StyledText widget, it works correctly. Is there something going on in the SourceViewer class that overrides setting doit=false?
My guess is that your listener is fired to late in the listener list. Remember that
StyledTextis not a native control and thus the handling of key, mouse, paint, resize, etc is handled by installing a listener on the canvas – seeStyledText.installListeners().If this listener is run before you have the chance to set
doit = false, then the key will already have been consumed.You might have a better change by hooking into the
SWT.Verifyevent though…