Handling KeyEvent in jface SourceViewer doesn't respect doit=false
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 overri开发者_如何学编程des setting doit=false?
My guess is that your listener is fired to late in the listener list. Remember that StyledText
is not a native control and thus the handling of key, mouse, paint, resize, etc is handled by installing a listener on the canvas - see StyledText.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.Verify
event though...
精彩评论