|
36 | 36 |
|
37 | 37 | /// Use this method to defer autocorrection. |
38 | 38 | @inlinable init(deferring:(snapshot: Snapshot, preference: Selection<Index>?)) { |
39 | | - self.snapshot = deferring.snapshot |
| 39 | + self.snapshot = deferring.snapshot |
40 | 40 | self.preference = deferring.preference |
41 | | - self.selection = Selection(snapshot.endIndex) |
| 41 | + self.selection = Selection(snapshot.endIndex) |
42 | 42 | } |
43 | 43 |
|
44 | 44 | //=------------------------------------------------------------------------= |
|
50 | 50 | //=--------------------------------------= |
51 | 51 | // Values |
52 | 52 | //=--------------------------------------= |
53 | | - let selection = selection.map( |
| 53 | + let selection = preference ?? selection.map( |
54 | 54 | lower: { Mismatches .forwards(from: self.snapshot[..<$0], to: snapshot).next }, |
55 | 55 | upper: { Mismatches.backwards(from: self.snapshot[$0...], to: snapshot).next }) |
56 | 56 | //=--------------------------------------= |
|
65 | 65 | // MARK: Transformations |
66 | 66 | //=------------------------------------------------------------------------= |
67 | 67 |
|
68 | | - /// Use this method to resolve a custom or deferred selection. |
| 68 | + /// Use this method to resolve selection. |
69 | 69 | @inlinable mutating func autocorrect() { |
70 | 70 | self.merge(selection: self.selection) |
71 | 71 | } |
|
75 | 75 | //=------------------------------------------------------------------------= |
76 | 76 |
|
77 | 77 | /// Use this method on changes to selection. |
78 | | - @inlinable mutating func merge(selection: Selection<Index>, momentums: Bool = false) { |
| 78 | + @inlinable mutating func merge(selection: Selection<Index>, resolve: Resolve = []) { |
79 | 79 | //=--------------------------------------= |
80 | 80 | // Accept Max Selection |
81 | 81 | //=--------------------------------------= |
82 | | - if selection == .max(snapshot) { |
| 82 | + if resolve.contains(.max), selection == .max(snapshot) { |
83 | 83 | self.selection = selection; return |
84 | 84 | } |
85 | 85 | //=--------------------------------------= |
|
93 | 93 | //=--------------------------------------= |
94 | 94 | var carets = selection.carets().detached() |
95 | 95 |
|
96 | | - if momentums { |
| 96 | + if resolve.contains(.momentums) { |
97 | 97 | carets.lower.momentum = Direction(from: self.selection.lower, to: selection.lower) |
98 | 98 | carets.upper.momentum = Direction(from: self.selection.upper, to: selection.upper) |
99 | 99 | } |
|
0 commit comments