2026-05-29 20:08:46 +02:00
|
|
|
import Foundation
|
|
|
|
|
|
|
|
|
|
public enum EditorActiveLineTracker {
|
|
|
|
|
public static func lines(from source: String, activeLineIndex: Int) -> [EditorLine] {
|
2026-05-30 18:19:52 +02:00
|
|
|
DocumentLineIndex(source: source).editorLines(activeLineIndex: activeLineIndex)
|
2026-05-29 20:08:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static func lineIndex(containing location: Int, in source: String) -> Int {
|
2026-05-30 18:19:52 +02:00
|
|
|
DocumentLineIndex(source: source).lineIndex(containing: location)
|
2026-05-29 20:08:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static func clampedSelection(_ selection: EditorSelection, in source: String) -> EditorSelection {
|
|
|
|
|
let sourceLength = source.utf16.count
|
|
|
|
|
let location = max(0, min(selection.location, sourceLength))
|
|
|
|
|
let length = max(0, min(selection.length, sourceLength - location))
|
|
|
|
|
return EditorSelection(location: location, length: length)
|
|
|
|
|
}
|
|
|
|
|
}
|