CustomWKWebView.swift
TLDR
This file contains a class called CustomWKWebView
that extends the WKWebView
class. It overrides the performKeyEquivalent
method to modify the key event behavior.
Classes
CustomWKWebView
This class extends the WKWebView
class. It overrides the performKeyEquivalent
method to modify the key event behavior. Specifically, it checks if the key event is a certain combination of modifiers (command, control, option) and character ('z'). If it's not, it calls the superclass implementation of performKeyEquivalent
. It then returns true
to prevent an error sound.
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import Foundation
import WebKit
class CustomWKWebView : WKWebView {
override func performKeyEquivalent(with event: NSEvent) -> Bool {
if (event.modifierFlags.contains(.command) && event.characters?.lowercased() != "z") ||
event.modifierFlags.contains(.control) ||
event.modifierFlags.contains(.option) {
return super.performKeyEquivalent(with: event)
}
super.performKeyEquivalent(with: event)
// Return true to prevent a "funk" error sound
return true
}
}