-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
moveLeft.swift
25 lines (24 loc) · 995 Bytes
/
moveLeft.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
public extension KeyboardMemory {
func moveLeft() -> Void {
if let current = self.current as? Placeholder {
guard let parentNode = current.parentNode else {
return
}
if let previousPlaceholder = parentNode.placeholders.firstBeforeOrNil(current) {
self.current = previousPlaceholder.nodes.last ?? previousPlaceholder
} else {
let ancestorPlaceholder = parentNode.parentPlaceholder!
let nodePreviousToParentOfCurrent = ancestorPlaceholder.nodes.firstBeforeOrNil(parentNode)
self.current = nodePreviousToParentOfCurrent ?? ancestorPlaceholder
}
} else {
if let current = self.current as? BranchingNode {
let placeholder = current.placeholders.last!
self.current = placeholder.nodes.last ?? placeholder
} else {
let current = self.current as! TreeNode
self.current = current.parentPlaceholder.nodes.firstBeforeOrNil(current) ?? current.parentPlaceholder
}
}
}
}