-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextAidProxy.swift
65 lines (55 loc) · 1.5 KB
/
TextAidProxy.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//
// TextAidProxy.swift
// keyboard-201606220-01
//
// Created by rocker on 20160903.
// Copyright © 2016 rocker. All rights reserved.
//
import UIKit
class TextAidProxy: NSObject, UIKeyInput {
// global vars and refs
var label: UILabel!
let documentProxy: UITextDocumentProxy
var tutRunner: TutRunner!
// global constants
let maxWidth: CGFloat = 30
init(documentProxy: UITextDocumentProxy) {
self.documentProxy = documentProxy
}
@objc func insertText(text: String) {
// send text to tut or docProxy
if !(tutRunner!.isRunning()) {
documentProxy.insertText(text)
refresh()
} else {
tutRunner!.testText(text)
}
}
@objc func deleteBackward() {
if tutRunner.isRunning() {
if label.text != nil {
label.text = String(label.text!.characters.dropLast())
}
} else {
documentProxy.deleteBackward()
refresh()
}
}
@objc func hasText() -> Bool {
return documentProxy.hasText()
}
func clear() {
label.text = ""
}
func refresh() {
if !tutRunner.isRunning() {
let displayText = documentProxy.documentContextBeforeInput
// short circuit eval
if displayText == nil || displayText!.characters.last == "\n" {
clear()
} else {
label.text = displayText!
}
}
}
}