Skip to content

Commit 641d367

Browse files
committed
Clean up review nits
1 parent 78cd390 commit 641d367

5 files changed

Lines changed: 12 additions & 29 deletions

File tree

Sources/TextDiff/AppKit/NSTextDiffView.swift

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,6 @@ public final class NSTextDiffView: NSView {
369369
scheduleHoverDismiss()
370370
}
371371

372-
private func clearHoverState() {
373-
cancelPendingHoverDismiss()
374-
clearHoverStateNow()
375-
}
376-
377372
private func clearHoverStateNow() {
378373
guard hoveredActionID != nil || hoveredIconRect != nil || isPointingHandCursorActive else {
379374
return
@@ -517,24 +512,6 @@ public final class NSTextDiffView: NSView {
517512
return false
518513
}
519514

520-
private func actionID(at point: CGPoint, layout: DiffLayout, context: DiffRevertInteractionContext) -> Int? {
521-
for actionID in context.runIndicesByActionID.keys.sorted() {
522-
guard let runIndices = context.runIndicesByActionID[actionID] else {
523-
continue
524-
}
525-
for runIndex in runIndices {
526-
guard layout.runs.indices.contains(runIndex),
527-
let chipRect = layout.runs[runIndex].chipRect else {
528-
continue
529-
}
530-
if chipRect.contains(point) {
531-
return actionID
532-
}
533-
}
534-
}
535-
return nil
536-
}
537-
538515
private func iconRect(for actionID: Int, context: DiffRevertInteractionContext) -> CGRect? {
539516
guard let unionRect = context.unionChipRectByActionID[actionID] else {
540517
return nil

Sources/TextDiff/TextDiffView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public struct TextDiffView: View {
134134
)
135135
}
136136
Divider()
137-
Text("Diff by words and revertable")
137+
Text("Diff by words and revertible")
138138
.bold()
139139
TextDiffView(
140140
original: "Add a diff view! Looks good!",

Tests/TextDiffTests/DiffLayouterPerformanceTests.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@ final class DiffLayouterPerformanceTests: XCTestCase {
3131
let updated = Self.replacingLastWord(in: original)
3232
let segments = TextDiffEngine.diff(original: original, updated: updated, mode: .character)
3333

34+
var lastLayout: DiffLayout?
3435
measure(metrics: [XCTClockMetric()]) {
35-
let layout = DiffTokenLayouter.layout(
36+
lastLayout = DiffTokenLayouter.layout(
3637
segments: segments,
3738
style: style,
3839
availableWidth: availableWidth,
3940
contentInsets: contentInsets
4041
)
41-
XCTAssertFalse(layout.runs.isEmpty)
4242
}
43+
XCTAssertFalse(lastLayout?.runs.isEmpty ?? true)
4344
}
4445

4546
private func runLayoutWithRevertInteractionsPerformanceTest(wordCount: Int) {
@@ -52,6 +53,8 @@ final class DiffLayouterPerformanceTests: XCTestCase {
5253
let updated = Self.replacingLastWord(in: original)
5354
let segments = TextDiffEngine.diff(original: original, updated: updated, mode: .token)
5455

56+
var lastLayout: DiffLayout?
57+
var lastContext: DiffRevertInteractionContext?
5558
measure(metrics: [XCTClockMetric()]) {
5659
let layout = DiffTokenLayouter.layout(
5760
segments: segments,
@@ -66,9 +69,11 @@ final class DiffLayouterPerformanceTests: XCTestCase {
6669
original: original,
6770
updated: updated
6871
)
69-
XCTAssertFalse(layout.runs.isEmpty)
70-
XCTAssertNotNil(context)
72+
lastLayout = layout
73+
lastContext = context
7174
}
75+
XCTAssertFalse(lastLayout?.runs.isEmpty ?? true)
76+
XCTAssertNotNil(lastContext)
7277
}
7378

7479
private static func largeText(wordCount: Int) -> String {

Tests/TextDiffTests/NSTextDiffSnapshotTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ final class NSTextDiffSnapshotTests: XCTestCase {
135135
size: CGSize(width: 320, height: 110),
136136
configureView: { view in
137137
view.isRevertActionsEnabled = true
138-
_ = view._testingSetHoveredFirstRevertAction()
138+
XCTAssertFalse(view._testingSetHoveredFirstRevertAction())
139139
},
140140
testName: "character_mode_no_affordance()"
141141
)

Tests/TextDiffTests/NSTextDiffViewTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ func hoverLeaveSchedulesDismissNotImmediate() {
272272
let centers = view._testingActionCenters()
273273
#expect(centers.count == 1)
274274
guard let center = centers.first else {
275+
Issue.record("Expected at least one action center")
275276
return
276277
}
277278

0 commit comments

Comments
 (0)