restores Helder in all its glory

This commit is contained in:
2026-09-28 11:34:49 +02:00
parent c2b38b853c
commit 1d29d0952d
280 changed files with 29205 additions and 7 deletions
+40
View File
@@ -0,0 +1,40 @@
import Foundation
public enum DiffViews {
/// The Actual view: the updated file with added lines tinted.
///
/// A run of removed lines with no added line beside it puts its rule on the edge of
/// the next surviving line (`gap: .above`), or under the last line when the run ends
/// the file (`gap: .below`). A run that also added lines gets no gap rule.
public static func actual(_ diff: Diff) -> [ViewLine] {
var above = Set<Int>()
var endsWithRemoval = false
var removed = 0, added = 0
func flush(nextNew: Int?) {
if removed > 0 && added == 0 {
if let nextNew { above.insert(nextNew) } else { endsWithRemoval = true }
}
removed = 0
added = 0
}
for row in diff.rows {
switch row.sign {
case .removed: removed += 1
case .added: added += 1
case .same: flush(nextNew: row.newNo)
}
}
flush(nextNew: nil)
let last = diff.right.last?.no
return diff.right.map { line in
let gap: GapEdge? = above.contains(line.no) ? .above : (endsWithRemoval && line.no == last ? .below : nil)
return ViewLine(no: line.no, text: line.text, style: line.mark == .added ? .added : nil, gap: gap)
}
}
/// A plain file with no diff, numbered from 1.
public static func plain(_ text: String) -> [ViewLine] {
LineDiff.droppingTrailingNewline(text).components(separatedBy: "\n").enumerated().map { ViewLine(no: $0.offset + 1, text: $0.element) }
}
}