在 jface SourceViewer 中处理 KeyEvent 不尊重 doit=false
我有一个正在修改的 JFace SourceViewer,我想捕获用户按下其中的 ENTER 键时的情况,执行一些代码,然后取消进一步执行 ENTER 事件。换句话说,我不想在 SourceViewer 文本中出现回车符。
我设置了一个 KeyListener 和一个 TraverseListener,并且它们都被正确触发,但是当我设置 evt.doit = false
时,回车符仍然显示在源查看器中。
如果我在 StyledText 小部件中执行相同的操作,它会正常工作。 SourceViewer 类中是否发生了覆盖设置 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 overrides setting doit=false?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的猜测是,您的侦听器在侦听器列表中被解雇得太晚了。请记住,
StyledText
不是本机控件,因此对按键、鼠标、绘画、调整大小等的处理是通过在画布上安装侦听器来处理的 - 请参阅StyledText.installListeners()
。如果在您有机会设置 doit = false 之前运行此侦听器,则密钥将已被消耗。
不过,通过挂钩
SWT.Verify
事件,您可能会有更好的改变......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 - 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.Verify
event though...