Skip to content

Commit edc9288

Browse files
committed
Enabled exit from field with TAB
1 parent 9777234 commit edc9288

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

Sources/Window.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public class Window {
142142
// Returns a string as entered by the user, providing for simple editing support using left and right arrows and the backspace
143143
// key. The input is collected from a field beginning at the specified position of a maximum length as specified.
144144
// If a fieldColorPair is specified Colors MUST be active. The field will then be displayed in the specified colorPair.
145+
// The function will exit when either TAB or ENTER is pressed
145146
public func getStringFromTextField(at fieldPosition:Point, maxCharacters:Int, fieldColorPair:ColorPair?) -> String {
146147
// Access keyboard
147148
let keyboard = Keyboard.shared
@@ -152,7 +153,7 @@ public class Window {
152153

153154
var string = ""
154155
var insertionPoint = string.startIndex
155-
var isEnter = false
156+
var shouldExit = false
156157
repeat {
157158
let key = keyboard.getKey(window:self)
158159
switch key.keyType {
@@ -214,18 +215,14 @@ public class Window {
214215
// Move the cursor forward
215216
cursor.position = cursor.position.offsetBy(xOffset:1, yOffset:0)
216217
}
217-
case .function1:
218-
cursor.pushPosition()
219-
cursor.position = Point(x:0, y:0)
220-
write(string)
221-
clearToEndOfLine()
222-
cursor.popPosition()
223218
case .isControl:
224-
isEnter = key.control! == 10
219+
let isEnter = key.control! == 10
220+
let isTab = key.control! == 9
221+
shouldExit = isEnter || isTab
225222
default:
226-
write("\(key.keyType)")
223+
do {}
227224
}
228-
} while !isEnter
225+
} while !shouldExit
229226

230227

231228
// Restore cursor position and return string

0 commit comments

Comments
 (0)