@@ -164,7 +164,9 @@ extension Context {
164164 //=------------------------------------------------------------------------=
165165
166166 /// Use this method on view update.
167- @inlinable public mutating func merge( _ status: Status , with cache: inout Cache ) -> Update {
167+ @inlinable public mutating func merge(
168+ _ status: Status , with cache: inout Cache ,
169+ and options: Synchronize ) throws -> Update {
168170 var update = Update ( )
169171 //=--------------------------------------=
170172 // Values
@@ -173,14 +175,20 @@ extension Context {
173175 if !values. merge ( status) { return update }
174176 let next = Self ( deferring: values, with: & cache, then: & update)
175177 //=--------------------------------------=
178+ // Validation
179+ //=--------------------------------------=
180+ if options. contains ( . invariant) , update. contains ( . value) {
181+ let input = Info . mark ( status. value)
182+ let output = Info . mark ( next . value)
183+ throw Info ( [ " input \( input) != \( output) output " ] )
184+ }
185+ //=--------------------------------------=
176186 // Update x Active == 2
177187 //=--------------------------------------=
178188 if layout != nil , next. layout != nil {
179189 self . unique ( )
180190 self . storage. status = next. status
181- self . storage. layout!. merge (
182- snapshot: /**/next. layout!. snapshot,
183- preference: next. layout!. preference)
191+ self . storage. layout!. merge ( next. layout!. snapshot, and: next. layout!. preference)
184192 //=--------------------------------------=
185193 // Update x Active <= 1
186194 //=--------------------------------------=
@@ -199,8 +207,9 @@ extension Context {
199207 //=------------------------------------------------------------------------=
200208
201209 /// Use this method on changes to text.
202- @inlinable public mutating func merge< T> ( _ characters: String ,
203- in range: Range < Offset < T > > , with cache: inout Cache ) throws -> Update {
210+ @inlinable public mutating func merge< T> (
211+ _ text: String , in range: Range < Offset < T > > ,
212+ with cache: inout Cache ) throws -> Update {
204213 var update = Update ( )
205214 //=--------------------------------------=
206215 // Layout
@@ -209,8 +218,7 @@ extension Context {
209218 //=--------------------------------------=
210219 // Values
211220 //=--------------------------------------=
212- let proposal = Proposal ( layout!. snapshot,
213- with: Snapshot ( characters) , in: /**/range)
221+ let proposal = Proposal ( layout!. snapshot, with: text, in: range)
214222 let commit = try status. resolve ( proposal, with: & cache)
215223 //=--------------------------------------=
216224 // Update
@@ -222,9 +230,7 @@ extension Context {
222230 self . unique ( )
223231 self . storage. status. value = commit. value
224232 self . storage. layout!. selection. collapse ( )
225- self . storage. layout!. merge (
226- snapshot: /**/commit. snapshot,
227- preference: commit. selection)
233+ self . storage. layout!. merge ( commit. snapshot, and: commit. selection)
228234 //=--------------------------------------=
229235 // Return
230236 //=--------------------------------------=
@@ -236,7 +242,8 @@ extension Context {
236242 //=------------------------------------------------------------------------=
237243
238244 /// Use this method on changes to selection.
239- @inlinable public mutating func merge< T> ( selection: Range < Offset < T > > , momentums: Bool ) -> Update {
245+ @inlinable public mutating func merge< T> (
246+ _ selection: Range < Offset < T > > , with options: Resolve ) -> Update {
240247 var update = Update ( )
241248 //=--------------------------------------=
242249 // Layout
@@ -245,16 +252,12 @@ extension Context {
245252 //=--------------------------------------=
246253 // Values
247254 //=--------------------------------------=
248- let selection = Selection (
249- layout!. snapshot. range ( at: selection) )
255+ let selection = Selection ( layout!. snapshot. range ( at: selection) )
250256 //=--------------------------------------=
251257 // Update
252258 //=--------------------------------------=
253259 self . unique ( )
254- self . storage. layout!. merge (
255- selection: selection,
256- resolve: [ . max, . momentums( momentums) ] )
257-
260+ self . storage. layout!. merge ( selection, with: options)
258261 update += . selection( layout!. selection != selection)
259262 //=--------------------------------------=
260263 // Return
0 commit comments