DebounceWebView.swift 706 B

12345678910111213141516171819202122232425
  1. //
  2. // SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
  3. // SPDX-License-Identifier: GPL-3.0-or-later
  4. //
  5. import WebKit
  6. class DebounceWebView: WKWebView {
  7. var previousPasteTimestamp: TimeInterval = .zero
  8. // See: https://developer.apple.com/forums/thread/696525?answerId=708067022#708067022
  9. override func paste(_ sender: Any?) {
  10. if NCUtils.isiOSAppOnMac() {
  11. let currentPasteTimestamp: TimeInterval = Date().timeIntervalSinceReferenceDate
  12. if currentPasteTimestamp - previousPasteTimestamp < 0.2 {
  13. return
  14. }
  15. previousPasteTimestamp = currentPasteTimestamp
  16. }
  17. super.paste(sender)
  18. }
  19. }