1717///
1818public struct Context < Style: DiffableTextStyle > {
1919 public typealias Value = Style . Value
20- public typealias State = DiffableTextKit . Remote < Style >
20+ public typealias Status = DiffableTextKit . Status < Style >
2121 public typealias Commit = DiffableTextKit . Commit < Value >
2222
2323 //=------------------------------------------------------------------------=
@@ -30,14 +30,14 @@ public struct Context<Style: DiffableTextStyle> {
3030 // MARK: Initializers
3131 //=------------------------------------------------------------------------=
3232
33- @inlinable init ( _ state : State , _ field : Field ) {
34- self . _storage = Storage ( state , field )
33+ @inlinable init ( _ status : Status , _ layout : Layout ) {
34+ self . _storage = Storage ( status , layout )
3535 }
3636
37- @inlinable public init ( _ state : State ) {
38- switch state . focus. wrapped {
39- case true : self = . focused( state . style, state . value)
40- case false : self = . unfocused( state . style, state . value)
37+ @inlinable public init ( _ status : Status ) {
38+ switch status . focus. wrapped {
39+ case true : self = . focused( status . style, status . value)
40+ case false : self = . unfocused( status . style, status . value)
4141 }
4242 }
4343
@@ -50,11 +50,11 @@ public struct Context<Style: DiffableTextStyle> {
5050 }
5151
5252 @inlinable static func focused( _ style: Style , _ commit: Commit ) -> Self {
53- Self ( State ( style, commit. value, true ) , Field ( ( commit. snapshot) ) )
53+ Self ( Status ( style, commit. value, true ) , Layout ( ( commit. snapshot) ) )
5454 }
5555
5656 @inlinable static func unfocused( _ style: Style , _ value: Value ) -> Self {
57- Self ( State ( style, value, false ) , Field ( Snapshot ( style. format ( value) , as: . phantom) ) )
57+ Self ( Status ( style, value, false ) , Layout ( Snapshot ( style. format ( value) , as: . phantom) ) )
5858 }
5959
6060 //=------------------------------------------------------------------------=
@@ -85,24 +85,24 @@ public struct Context<Style: DiffableTextStyle> {
8585 // MARK: State
8686 //=--------------------------------------------------------------------=
8787
88- @usableFromInline var state : State
89- @usableFromInline var field : Field
88+ @usableFromInline var status : Status
89+ @usableFromInline var layout : Layout
9090
9191 //=--------------------------------------------------------------------=
9292 // MARK: Initializers
9393 //=--------------------------------------------------------------------=
9494
95- @inlinable init ( _ state : State , _ field : Field ) {
96- self . state = state
97- self . field = field
95+ @inlinable init ( _ status : Status , _ layout : Layout ) {
96+ self . status = status
97+ self . layout = layout
9898 }
9999
100100 //=--------------------------------------------------------------------=
101101 // MARK: Utilities
102102 //=--------------------------------------------------------------------=
103103
104104 @inlinable func copy( ) -> Self {
105- Self ( state , field )
105+ Self ( status , layout )
106106 }
107107 }
108108}
@@ -117,45 +117,45 @@ public extension Context {
117117 // MARK: 1st
118118 //=------------------------------------------------------------------------=
119119
120- @inlinable internal var state : State {
121- _storage. state
120+ @inlinable internal var status : Status {
121+ _storage. status
122122 }
123123
124- @inlinable internal var field : Field {
125- _storage. field
124+ @inlinable internal var layout : Layout {
125+ _storage. layout
126126 }
127127
128128 //=------------------------------------------------------------------------=
129129 // MARK: 2nd
130130 //=------------------------------------------------------------------------=
131131
132132 @inlinable var style : Style {
133- state . style
133+ status . style
134134 }
135135
136136 @inlinable var value : Value {
137- state . value
137+ status . value
138138 }
139139
140140 @inlinable var focus : Focus {
141- state . focus
141+ status . focus
142142 }
143143
144144 //=------------------------------------------------------------------------=
145145 // MARK: 3rd
146146 //=------------------------------------------------------------------------=
147147
148148 @inlinable var snapshot : Snapshot {
149- field . snapshot
149+ layout . snapshot
150150 }
151151
152152 @inlinable var text : String {
153- field . snapshot. characters
153+ layout . snapshot. characters
154154 }
155155
156156 @inlinable func selection< T> ( as type: Position < T > . Type =
157157 Position< T> . self ) -> Range < T . Position > where T: Offset {
158- field . positions ( at: field . selection) . bounds
158+ layout . positions ( at: layout . selection) . bounds
159159 }
160160}
161161
@@ -175,8 +175,8 @@ public extension Context {
175175 //=--------------------------------------=
176176 if other. focus. wrapped {
177177 self . write {
178- $0. state = other. state
179- $0. field . update ( snapshot: other. snapshot)
178+ $0. status = other. status
179+ $0. layout . update ( snapshot: other. snapshot)
180180 }
181181 //=--------------------------------------=
182182 // Unfocused
@@ -185,22 +185,20 @@ public extension Context {
185185 }
186186
187187 //=------------------------------------------------------------------------=
188- // MARK: Remote
188+ // MARK: Status
189189 //=------------------------------------------------------------------------=
190190
191- @inlinable mutating func merge( _ remote : State ) -> Bool {
191+ @inlinable mutating func merge( _ status : Status ) -> Bool {
192192 //=--------------------------------------=
193193 // Update
194194 //=--------------------------------------=
195- let ( result, update) = self . state + remote
195+ let ( result, update) = self . status + status
196196 //=--------------------------------------=
197- // At Least On Value Must Be Unique
197+ // At Least One Must Be Different
198198 //=--------------------------------------=
199- guard !update. isEmpty else { return false }
200- //=--------------------------------------=
201- // Insert
202- //=--------------------------------------=
203- self . merge ( Self ( result) ) ; return true
199+ return ( !update. isEmpty) . on ( true ) {
200+ self . merge ( Self . init ( result) )
201+ }
204202 }
205203
206204 //=------------------------------------------------------------------------=
@@ -212,7 +210,7 @@ public extension Context {
212210 //=--------------------------------------=
213211 // Values
214212 //=--------------------------------------=
215- let carets = field . indices ( at: Carets ( range) )
213+ let carets = layout . indices ( at: Carets ( range) )
216214 let commit = try style. merge ( Proposal (
217215 snapshot, with: characters, in: carets. bounds) )
218216 //=--------------------------------------=
@@ -227,10 +225,10 @@ public extension Context {
227225 //=------------------------------------------------------------------------=
228226
229227 @inlinable internal mutating func set( selection: Index ) {
230- self . write ( { $0. field . selection = Carets ( selection) } )
228+ self . write ( { $0. layout . selection = Carets ( selection) } )
231229 }
232230
233231 @inlinable mutating func update< T> ( selection: Range < T . Position > , momentum: Bool ) where T: Offset {
234- self . write ( { $0. field . update ( selection: Carets ( selection) , momentum: momentum) } )
232+ self . write ( { $0. layout . update ( selection: Carets ( selection) , momentum: momentum) } )
235233 }
236234}
0 commit comments