Skip to content

Commit caa892c

Browse files
lintkirb
authored andcommitted
[ios] add ability to hold arrow keys
This adds the ability to hold the up/down/left/right arrow keys to move the cursor or navigate through bash history.
1 parent 01b266e commit caa892c

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

iOS/UI/Keyboard/TerminalKeyInput.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class TerminalKeyInput: TextInputBase {
3131
private let leftKey = KeyboardButton(title: "Left", systemImage: "arrowtriangle.left", systemHighlightedImage: "arrowtriangle.left.fill", image: #imageLiteral(resourceName: "key-left"), highlightedImage: #imageLiteral(resourceName: "key-left-down"))
3232
private let rightKey = KeyboardButton(title: "Right", systemImage: "arrowtriangle.right", systemHighlightedImage: "arrowtriangle.right.fill", image: #imageLiteral(resourceName: "key-right"), highlightedImage: #imageLiteral(resourceName: "key-right-down"))
3333

34+
private var longPressTimer: Timer?
3435
private var buttons: [KeyboardButton]!
3536
private var squareButtonConstraints: [NSLayoutConstraint]!
3637
private var moreToolbar = KeyboardPopupToolbar(frame: .zero)
@@ -159,6 +160,11 @@ class TerminalKeyInput: TextInputBase {
159160
moreToolbar.deleteKey.addTarget(self, action: #selector(self.deleteKeyPressed), for: .touchUpInside)
160161
moreToolbar.settingsKey.addTarget(self, action: #selector(self.settingsKeyPressed), for: .touchUpInside)
161162

163+
for key in [ upKey, downKey, leftKey, rightKey ] {
164+
let gestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(self.arrowKeyLongPressed(_:)))
165+
key.addGestureRecognizer(gestureRecognizer)
166+
}
167+
162168
let views: [String: UIView] = [
163169
"ctrlKey": ctrlKey,
164170
"metaKey": metaKey,
@@ -290,6 +296,41 @@ class TerminalKeyInput: TextInputBase {
290296
@objc func settingsKeyPressed() {
291297
terminalInputDelegate!.openSettings()
292298
}
299+
300+
@objc func arrowKeyLongPressed(_ sender: UILongPressGestureRecognizer) {
301+
switch sender.state {
302+
case .began:
303+
switch sender.view! {
304+
case upKey:
305+
longPressTimer = Timer.scheduledTimer(timeInterval: 0.2, target: self, selector: #selector(upKeyPressed), userInfo: nil, repeats: true)
306+
break
307+
308+
case downKey:
309+
longPressTimer = Timer.scheduledTimer(timeInterval: 0.2, target: self, selector: #selector(downKeyPressed), userInfo: nil, repeats: true)
310+
break
311+
312+
case leftKey:
313+
longPressTimer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(leftKeyPressed), userInfo: nil, repeats: true)
314+
break
315+
316+
case rightKey:
317+
longPressTimer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(rightKeyPressed), userInfo: nil, repeats: true)
318+
break
319+
320+
default:
321+
break
322+
}
323+
break
324+
325+
case .ended, .cancelled:
326+
longPressTimer?.invalidate()
327+
longPressTimer = nil
328+
break
329+
330+
default:
331+
break
332+
}
333+
}
293334

294335
// MARK: - More row
295336

0 commit comments

Comments
 (0)