在 jface SourceViewer 中处理 KeyEvent 不尊重 doit=false

发布于 2024-11-16 16:16:44 字数 316 浏览 0 评论 0原文

我有一个正在修改的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风渺 2024-11-23 16:16:44

我的猜测是,您的侦听器在侦听器列表中被解雇得太晚了。请记住,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 - 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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文