Skip to content

Commit 07ef4c6

Browse files
committed
Yet another little Prefix optimization.
1 parent f914a74 commit 07ef4c6

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Sources/DiffableTextKit/Styles/Prefix.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,18 @@ public struct PrefixTextStyle<Base: DiffableTextStyle>: WrapperTextStyle {
8383
//=--------------------------------------=
8484
// Base x Some
8585
//=--------------------------------------=
86-
let size = snapshot.count
86+
let start = snapshot.endIndex
8787
snapshot.append(contentsOf: base)
8888
//=--------------------------------------=
8989
// Base x Some x Selection
9090
//=--------------------------------------=
9191
guard let selection = base.selection else { return }
92-
let min = selection.lower.attribute + size // offset
93-
let max = selection.upper.attribute + size // offset
94-
95-
let lower = snapshot.index(snapshot.startIndex, offsetBy: min)
96-
let upper = snapshot.index(lower, /*---*/ offsetBy: max - min)
97-
snapshot.selection = Selection.init(unchecked: (lower, upper))
92+
let min = selection .lower.attribute
93+
let max = selection .upper.attribute
94+
95+
let lower = snapshot.index(start, offsetBy: min)
96+
let upper = snapshot.index(lower, offsetBy: max - min)
97+
snapshot.select(Range(uncheckedBounds:(lower, upper)))
9898
}
9999
}
100100

0 commit comments

Comments
 (0)