support EditSession in filterKeyDown/filterKeyUp #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
我在开发的时候,遇到一个需求无法实现:
我希望在 filterKeyDown 事件时,发现按了并非输入法范畴的按键。这个时候,希望输入法判断,前面的输入其实也并非在输入中文,这个时候直接把 composition 提交最好。
应用场景非常广泛,比如在编写代码或在控制台敲指令的时候,经常出现误打开了中文输入的情况。这时多按一次中英切换显得很多余。
但是 filterKeyDown 目前没有 EditSession 对象,所以不能提交。我尝试让 filterKeyDown 返回 true,并在 onKeyDown 时再提交,并返回 false ,放弃最后一个按键,结果发现行不通。
似乎过了 testkeydown 后,TSF 就不再检查 onkeydown 的返回值了。
比较好的方法是在 filterkeydown 时也创建出 EditSession 对象来。这个 PR 做了这样的修改。这并不会破坏之前的代码(不过 PIME 里也需要做一点改动, 给 filterkeydown 等 callback 函数加上 EditSession 参数)。但是可以增强 filterKeyDown/filterKeyUp 的处理能力。
希望能够把这个 pr 合并到主干。 :D