main

mattermost/focalboard

Last updated at: 29/12/2023 09:39

CustomWKWebView.swift

TLDR

This file defines a custom subclass of WKWebView called CustomWKWebView.

Methods

performKeyEquivalent(_: NSEvent) -> Bool

This method overrides the performKeyEquivalent method from WKWebView. It checks if the event is a key equivalent for certain modifiers (command, control, and option). If it is not, it calls the super implementation of performKeyEquivalent. It then returns true to prevent a "funk" error sound.

Classes

CustomWKWebView

This class is a subclass of WKWebView. It overrides the performKeyEquivalent method to handle key equivalents for specific modifiers. It prevents a "funk" error sound by returning true after calling the super implementation of performKeyEquivalent.

// 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
	}
}