捕获 SproutCore 中的删除/退格键
我有一个 SproutCore 窗格(具体来说是一个 PalettePane),其中包含一个与屏幕上其他位置的对象绑定的表单。窗格导致对象删除交互出现问题。我希望它的工作方式是:
- 如果文本输入字段处于焦点,则退格/删除键应应用于这些字段(即编辑文本)
- 如果没有文本输入字段具有焦点,则退格/删除键应删除与表单相关的所选对象。 (当用户选择一个对象时,该窗格就会出现,因此,如果该窗格存在,则存在一个选定的对象。)
到目前为止,我得到了这些行为之一或另一个,而不是两者兼有。如果我在窗格中设置 acceptsKeyPane: YES
,我会得到应用于文本字段的退格/删除键,但当文本字段没有焦点时不会删除所选对象。如果我使用 acceptsKeyPane: NO
,当我编辑文本字段并按退格键时,它会删除我尝试编辑的对象。
雪上加霜的是,在带有 acceptsKeyPane: YES
的 Firefox 中,退格键会被浏览器捕获并解释为后退按钮单击,这会让用户感到沮丧。
我查看了 root_responder.js
代码,看起来 SproutCore 对 Firefox 的退格处理方式有所不同,但如果我可以按照上面的描述处理它们,那么 FF 和其他浏览器之间的区别就没有什么意义了。
预计 2011 年 5 月:阅读此处的答案时请记住,1.5、1.6 及更高版本的 SproutCore API 可能与此不同。
I have a SproutCore Pane - a PalettePane, specifically - which includes a form tied to an object elsewhere on the screen. The Pane is causing trouble with the object deletion interaction. The way I want it to work is:
- If a text input field is in focus, the backspace/delete keys should apply to those fields (i.e. editing the text)
- If no text input field has focus, the backspace/delete keys should delete the selected object related to the form. (The pane appears when the user has selected an object, so if the pane exists there's a selected object.)
So far, I get one of these behaviors or the other, never both. If I set acceptsKeyPane: YES
in the Pane, I get the backspace/delete keys applying to the text fields, but no deleting of selected objects when the text fields don't have focus. If I use acceptsKeyPane: NO
, when I'm editing a text field and hit backspace, it deletes the object I was trying to edit.
To add insult to injury, in Firefox with acceptsKeyPane: YES
the backspace key is caught by the browser and interpreted as a back-button click, which is going to be frustrating to the user.
I've looked at the root_responder.js
code and it looks like SproutCore handles backspaces differently for Firefox, but if I can handle them as described above the distinction between FF and other browsers should be moot.
ETA May 2011: Bear in mind when reading answers here that the SproutCore API for 1.5, 1.6 and beyond may not be the same as this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们最终是这样完成的:
becomeFirstResponder()
。acceptsFirstResponder: YES
添加到其视图定义中。...这就成功了。
Here's how we finally wound up doing it:
becomeFirstResponder()
on it.acceptsFirstResponder: YES
to its view definition....and that did the trick.