You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+62Lines changed: 62 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -80,6 +80,66 @@ TextDiffView(
80
80
-`.token` (default): token-level diff behavior.
81
81
-`.character`: refines adjacent word replacements by character so shared parts remain unchanged text (for example `Add` -> `Added` shows unchanged `Add` and inserted `ed`).
82
82
83
+
## Engine-Only Results
84
+
85
+
You can compute a reusable diff result without rendering a view:
86
+
87
+
```swift
88
+
importTextDiff
89
+
90
+
let result = TextDiffEngine.result(
91
+
original: "Track old values in storage.",
92
+
updated: "Track new values in storage.",
93
+
mode: .token
94
+
)
95
+
96
+
for change in result.changes {
97
+
print(change.kind, change.text)
98
+
}
99
+
100
+
print(result.summary.insertedCharacters)
101
+
print(result.summary.deletedCharacters)
102
+
```
103
+
104
+
`TextDiffResult.changes` preserves the computed diff order for the selected mode and uses UTF-16 offsets/lengths so it can be stored and replayed consistently later. Summaries are derived from those mode-specific change records.
105
+
106
+
## Precomputed Rendering
107
+
108
+
If you already computed a diff result for storage or analytics, you can render it later without recomputing:
109
+
110
+
```swift
111
+
importSwiftUI
112
+
importTextDiff
113
+
114
+
let result = TextDiffEngine.result(
115
+
original: "Track old values in storage.",
116
+
updated: "Track new values in storage.",
117
+
mode: .token
118
+
)
119
+
120
+
structStoredDiffView: View {
121
+
var body: some View {
122
+
TextDiffView(result: result)
123
+
.padding()
124
+
}
125
+
}
126
+
```
127
+
128
+
AppKit has the same precomputed rendering path:
129
+
130
+
```swift
131
+
importAppKit
132
+
importTextDiff
133
+
134
+
let result = TextDiffEngine.result(
135
+
original: "Track old values in storage.",
136
+
updated: "Track new values in storage.",
137
+
mode: .token
138
+
)
139
+
140
+
let diffView =NSTextDiffView(result: result)
141
+
```
142
+
83
143
## Custom Styling
84
144
85
145
```swift
@@ -123,8 +183,10 @@ Change-specific colors and text treatment live under `additionsStyle` and `remov
123
183
- Matching is exact (case-sensitive and punctuation-sensitive).
124
184
- Replacements are rendered as adjacent delete then insert segments.
125
185
- Character mode refines adjacent word replacements only; punctuation and whitespace keep token-level behavior.
186
+
-`TextDiffResult.changes` and `TextDiffResult.summary` are mode-specific outputs; `.token` and `.character` results are not normalized to each other.
126
187
- Whitespace changes preserve the `updated` layout and stay visually neutral (no chips).
127
188
- Rendering is display-only (not selectable) to keep chip geometry deterministic.
189
+
- Result-driven rendering (`TextDiffView(result:)`, `NSTextDiffView(result:)`) is display-only and does not enable revert actions.
128
190
-`interChipSpacing` controls spacing between adjacent changed lexical chips (words or punctuation).
129
191
-`lineSpacing` controls vertical spacing between wrapped lines.
130
192
- Chip horizontal padding is preserved with a minimum effective floor of 3pt per side.
0 commit comments