Skip to content

Commit eaf52fd

Browse files
committed
Improved: Prefix
1 parent f27d87d commit eaf52fd

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Sources/DiffableTextKit/Styles/Prefix.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,14 @@ public struct PrefixTextStyle<Base: DiffableTextStyle>: WrapperTextStyle {
5959

6060
@inlinable func label(_ commit: inout Commit<Value>) {
6161
guard !prefix.isEmpty else { return }
62-
let selection = commit.snapshot.selection
63-
let prefix = Snapshot(prefix,as:.phantom)
62+
let base = commit.snapshot
6463

65-
commit.snapshot = prefix + commit.snapshot
64+
commit.snapshot = Snapshot(prefix, as: .phantom)
65+
let size = commit.snapshot.count /*-----------*/
66+
commit.snapshot.append(contentsOf: /*---*/ base)
6667

67-
guard let selection else { return }
68-
let offsets = selection.map({ prefix.count + $0.attribute })
68+
guard let selection = base.selection else { return }
69+
let offsets = selection.map({ size + $0.attribute })
6970
let lower = commit.snapshot.index(commit.snapshot.startIndex, offsetBy: offsets.lower)
7071
let upper = commit.snapshot.index(lower/*-*/, offsetBy: offsets.upper - offsets.lower)
7172
commit.snapshot.select(Range(uncheckedBounds: (lower, upper)))

0 commit comments

Comments
 (0)