@@ -163,27 +163,42 @@ public extension Context {
163163// MARK: Transformations
164164//=----------------------------------------------------------------------------=
165165
166- public extension Context {
166+ extension Context {
167167
168168 //=------------------------------------------------------------------------=
169169 // MARK: Context
170170 //=------------------------------------------------------------------------=
171171
172- @inlinable internal mutating func merge( _ other: Self ) {
172+ @inlinable mutating func merge( _ other: Self ) {
173173 //=--------------------------------------=
174- // Focused
174+ // Active
175175 //=--------------------------------------=
176176 if other. focus == true {
177177 self . write {
178178 $0. status = other. status
179179 $0. layout. merge ( snapshot: other. snapshot)
180180 }
181181 //=--------------------------------------=
182- // Unfocused
182+ // Inactive
183183 //=--------------------------------------=
184184 } else { self = other }
185185 }
186186
187+ //=------------------------------------------------------------------------=
188+ // MARK: Selection
189+ //=------------------------------------------------------------------------=
190+
191+ @inlinable mutating func collapse( ) {
192+ self . write ( { $0. layout. selection. collapse ( ) } )
193+ }
194+ }
195+
196+ //=----------------------------------------------------------------------------=
197+ // MARK: Transformations
198+ //=----------------------------------------------------------------------------=
199+
200+ public extension Context {
201+
187202 //=------------------------------------------------------------------------=
188203 // MARK: Status
189204 //=------------------------------------------------------------------------=
@@ -201,7 +216,7 @@ public extension Context {
201216 //=--------------------------------------=
202217 // Update
203218 //=--------------------------------------=
204- self . merge ( Self . init ( next) )
219+ self . merge ( Self ( next) )
205220 //=--------------------------------------=
206221 // Return
207222 //=--------------------------------------=
@@ -218,13 +233,13 @@ public extension Context {
218233 //=--------------------------------------=
219234 // Values
220235 //=--------------------------------------=
221- let carets = layout . indices ( at : Carets ( range ) )
222- let commit = try style . merge ( Proposal (
223- snapshot , with : characters , in : carets . range) )
236+ let commit = try style . resolve ( Proposal (
237+ update : snapshot , with : characters , in :
238+ layout . indices ( at : Carets ( range ) ) . range) )
224239 //=--------------------------------------=
225240 // Update
226241 //=--------------------------------------=
227- self . set ( selection : carets . upperBound )
242+ self . collapse ( )
228243 self . merge ( Self . focused ( style, commit) )
229244 //=--------------------------------------=
230245 // Return
@@ -236,12 +251,20 @@ public extension Context {
236251 // MARK: Selection
237252 //=------------------------------------------------------------------------=
238253
239- @inlinable internal mutating func set( selection: Index ) {
240- self . write ( { $0. layout. selection = Carets ( selection) } )
241- }
242-
243- @inlinable mutating func merge< T> ( selection: Range < T . Position > , momentums: Bool ) -> Update where T: Offset {
244- self . write ( { $0. layout . merge ( selection: Carets ( selection) , momentums: momentums) } )
245- return Update . selection ( selection != self . selection ( ) )
254+ @inlinable mutating func merge< T> (
255+ selection: Range < T . Position > ,
256+ momentums: Bool ) -> Update where T: Offset {
257+ //=--------------------------------------=
258+ // Update
259+ //=--------------------------------------=
260+ self . write {
261+ $0. layout. merge (
262+ selection: Carets ( selection) ,
263+ momentums: momentums)
264+ }
265+ //=--------------------------------------=
266+ // Return
267+ //=--------------------------------------=
268+ return . selection( selection != self . selection ( ) )
246269 }
247270}
0 commit comments