Skip to content

Commit

Permalink
Merge pull request #268 from iOSappssolutions/main
Browse files Browse the repository at this point in the history
[bug fix]  fix incidental double tap on up arrow
  • Loading branch information
migueldeicaza committed Jan 5, 2023
2 parents d51163c + 90073b4 commit 2394693
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Sources/SwiftTerm/iOS/iOSAccessoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,20 @@ public class TerminalAccessory: UIInputView, UIInputViewAudioFeedback {
// Controls the timer for auto-repeat
var repeatCommand: (() -> ())? = nil
var repeatTimer: Timer?
var repeatTask: Task<(), Never>?

func startTimerForKeypress (repeatKey: @escaping () -> ())
{
repeatKey ()
repeatCommand = repeatKey
repeatTimer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { timer in
self.repeatCommand? ()

repeatTask = Task {
try? await Task.sleep(nanoseconds: 600_000_000)
guard !(repeatTask?.isCancelled ?? true) else { return }
let rc = self.repeatCommand
self.repeatTimer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { timer in
rc? ()
}
}
}

Expand All @@ -104,6 +111,7 @@ public class TerminalAccessory: UIInputView, UIInputViewAudioFeedback {
repeatTimer?.invalidate()
repeatCommand = nil
repeatTimer = nil
repeatTask?.cancel()
}

@objc func up (_ sender: UIButton)
Expand Down

0 comments on commit 2394693

Please sign in to comment.