Skip to content

Commit

Permalink
Do not intercept characters typed into input boxes
Browse files Browse the repository at this point in the history
In order to allow some user interaction on the article view, we need
WkWebView to behave like legacy WebView on <input> and <textarea>
elements.

Issue #1793
  • Loading branch information
barijaona committed Aug 26, 2024
1 parent 4591504 commit 7e635ab
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Vienna/Sources/Main window/WebKitArticleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,19 @@ class WebKitArticleView: CustomWKWebView, ArticleContentView, WKNavigationDelega

/// handle special keys when the article view has the focus
override func keyDown(with event: NSEvent) {
if let pressedKeys = event.characters, pressedKeys.count == 1 {
var interceptKey = true
waitForAsyncExecution(until: DispatchTime.now() + DispatchTimeInterval.milliseconds(200)) { finishHandler in
self.evaluateJavaScript("document.activeElement.tagName") { res, _ in
guard let res = res as? String else {
return
}
if ["INPUT", "TEXTAREA"].contains(res) {
interceptKey = false
}
finishHandler()
}
}
if interceptKey, let pressedKeys = event.characters, pressedKeys.count == 1 {
let pressedKey = (pressedKeys as NSString).character(at: 0)
// give app controller preference when handling commands
if NSApp.appController.handleKeyDown(pressedKey, withFlags: event.modifierFlags.rawValue) {
Expand Down

0 comments on commit 7e635ab

Please sign in to comment.