Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
oscbyspro committed May 20, 2022
1 parent c01616f commit 1b60cc7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 27 deletions.
36 changes: 22 additions & 14 deletions Sources/DiffableTextKit/Models/Context.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public struct Context<Style: DiffableTextStyle> {
// MARK: Transformation
//=------------------------------------------------------------------------=

/// Transforms this instance with copy-on-write behavior.
/// Writes to storage with copy-on-write behavior.
@inlinable mutating func write(_ write: (Storage) -> Void) {
//=--------------------------------------=
// Unique
Expand Down Expand Up @@ -111,49 +111,57 @@ public struct Context<Style: DiffableTextStyle> {
// MARK: Accessors
//=----------------------------------------------------------------------------=

public extension Context {
extension Context {

//=------------------------------------------------------------------------=
// MARK: 1st
//=------------------------------------------------------------------------=

@inlinable internal var status: Status {
@inlinable @inline(__always)
var status: Status {
_storage.status
}

@inlinable internal var layout: Layout {
@inlinable @inline(__always)
var layout: Layout {
_storage.layout
}

//=------------------------------------------------------------------------=
// MARK: 2nd
//=------------------------------------------------------------------------=

@inlinable var style: Style {
@inlinable @inline(__always)
public var style: Style {
status.style
}

@inlinable var value: Value {
@inlinable @inline(__always)
public var value: Value {
status.value
}

@inlinable var focus: Focus {
@inlinable @inline(__always)
public var focus: Focus {
status.focus
}

//=------------------------------------------------------------------------=
// MARK: 3rd
//=------------------------------------------------------------------------=

@inlinable var snapshot: Snapshot {
@inlinable @inline(__always)
public var snapshot: Snapshot {
layout.snapshot
}

@inlinable var text: String {
@inlinable @inline(__always)
public var text: String {
layout.snapshot.characters
}

@inlinable func selection<T>(as type: Position<T>.Type =
@inlinable @inline(__always)
public func selection<T>(as position: Position<T>.Type =
Position<T>.self) -> Range<T.Position> where T: Offset {
layout.selection().range
}
Expand Down Expand Up @@ -197,13 +205,13 @@ extension Context {
// MARK: Transformations
//=----------------------------------------------------------------------------=

public extension Context {
extension Context {

//=------------------------------------------------------------------------=
// MARK: Status
//=------------------------------------------------------------------------=

@inlinable mutating func merge(_ status: Status) -> Update {
@inlinable public mutating func merge(_ status: Status) -> Update {
//=--------------------------------------=
// Update
//=--------------------------------------=
Expand All @@ -227,7 +235,7 @@ public extension Context {
// MARK: Characters
//=------------------------------------------------------------------------=

@inlinable mutating func merge<T>(_ characters: String,
@inlinable public mutating func merge<T>(_ characters: String,
in range: Range<T.Position>) throws -> Update where T: Offset {
let previous = value
//=--------------------------------------=
Expand All @@ -251,7 +259,7 @@ public extension Context {
// MARK: Selection
//=------------------------------------------------------------------------=

@inlinable mutating func merge<T>(
@inlinable public mutating func merge<T>(
selection: Range<T.Position>,
momentums: Bool) -> Update where T: Offset {
//=--------------------------------------=
Expand Down
7 changes: 0 additions & 7 deletions Sources/DiffableTextKitXNumber/Aliases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,3 @@ extension _OptionalNumberTextStyle where Format: NumberTextFormatXCurrencyable {
extension _OptionalNumberTextStyle where Format: NumberTextFormatXPercentable {
public typealias Percent = _OptionalNumberTextStyle<Format.Percent>
}

//*============================================================================*
// MARK: Helpers
//*============================================================================*

public typealias NFSC = NumberFormatStyleConfiguration
public typealias CFSC = CurrencyFormatStyleConfiguration
3 changes: 3 additions & 0 deletions Sources/DiffableTextKitXNumber/Format.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ FormatInput: DiffableTextKitXNumber.NumberTextValue {
associatedtype NumberTextRoundingIncrement
associatedtype NumberTextSign: NumberTextFormatXSignRepresentable
associatedtype NumberTextScheme: DiffableTextKitXNumber.NumberTextScheme

typealias NFSC = NumberFormatStyleConfiguration
typealias CFSC = CurrencyFormatStyleConfiguration

//=------------------------------------------------------------------------=
// MARK: State
Expand Down
7 changes: 4 additions & 3 deletions Sources/DiffableTextKitXNumber/Models/Precision.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Foundation

public struct NumberTextPrecision<Value: NumberTextValue>: Equatable {
@usableFromInline typealias Name = _Precision
@usableFromInline typealias Mode = NumberFormatStyleConfiguration.Precision

//=------------------------------------------------------------------------=
// MARK: State
Expand Down Expand Up @@ -87,19 +88,19 @@ public struct NumberTextPrecision<Value: NumberTextValue>: Equatable {
// MARK: Utilities
//=------------------------------------------------------------------------=

@inlinable func inactive() -> NFSC.Precision {
@inlinable func inactive() -> Mode {
.integerAndFractionLength(
integerLimits: integer.lowerBound ... Int.max,
fractionLimits: fraction.lowerBound ... Int.max)
}

@inlinable func active() -> NFSC.Precision {
@inlinable func active() -> Mode {
.integerAndFractionLength(
integerLimits: Name.lower.integer ... integer.upperBound,
fractionLimits: Name.lower.fraction ... fraction.upperBound)
}

@inlinable func interactive(_ count: Count) -> NFSC.Precision {
@inlinable func interactive(_ count: Count) -> Mode {
.integerAndFractionLength(
integerLimits: max(Name.lower.integer, count.integer) ... count.integer,
fractionLimits: max(Name.lower.fraction, count.fraction) ... count.fraction)
Expand Down
6 changes: 3 additions & 3 deletions Sources/DiffableTextKitXNumber/Value+Floats.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Foundation
// MARK: Declaration
//*============================================================================*

private protocol _Value:
private protocol _Float:
NumberTextValueXSigned,
NumberTextValueXFloatingPoint,
NumberTextValueXNumberable,
Expand All @@ -24,7 +24,7 @@ NumberTextValueXPercentable { }
// MARK: Decimal
//*============================================================================*

extension Decimal: _Value {
extension Decimal: _Float {
public typealias NumberTextStyle = _NumberTextStyle<FormatStyle>

//=------------------------------------------------------------------------=
Expand All @@ -40,7 +40,7 @@ extension Decimal: _Value {
// MARK: Double
//*============================================================================*

extension Double: _Value {
extension Double: _Float {
public typealias NumberTextStyle = _NumberTextStyle<FloatingPointFormatStyle<Self>>

//=------------------------------------------------------------------------=
Expand Down

0 comments on commit 1b60cc7

Please sign in to comment.