cocoa - WKWebView in Cocoa app can't get the cursor on click
问题描述
I created a simple test app where one field is an NSTextField
and another is a <textarea>
instead a WKWebView
. I can click into the web view once, but if I go back to the NSTextField
, I'm unable to get the cursor back into the web view ever again.
Here's a demonstration:
As you can see, the web view is still interactive to some extent, it just can't become (I assume) the first responder again.
Is there something weird about WKWebView
and the responder chain? How can I make the WebWebView
behave like a normal NSTextField
?
Here is a sample project built in Xcode 11.5 in case you want to try it out.
How can this be fixed?
解决方案
The issue seems to be related to the textarea, using content editable <body contenteditable="true"></body>
does seem to work.
A workaround for using the textarea is to subclass WKWebView like this:
- (void)mouseDown:(NSEvent *)event
{
[super mouseDown:event];
[[self window] makeFirstResponder:self];
}
推荐阅读
- list - 如何从现有对象列表中创建新对象列表?
- python - 从大字典中删除元素,就地
- sql - 仅在 PostgreSQL 中使用带有选定值的过滤器对列值求和
- excel - XML 中的节点似乎无法识别/可利用
- java - 在实现带有片段的 TabLayout 时获得 NoClassDefFoundError 并且在片段内部想要使用回收器视图
- reactjs - 只有在我返回单元格编辑后,React-Bootstrap-Table2 的单元格才会刷新
- c - malloc sizeof 结构的各个成员?
- python - python代码不正确。不符合所列要求
- php - Laravel eloquent order by sum of hasMany 或 by join
- go - 如何使用动态数组