The capture gate and the chunk size were the same number, so a selection above one chunk was rejected before the pipeline could split it; the Settings sliders moved both thresholds together. Add maximumPartsPerSelection (1-8, default 1, so existing behaviour is unchanged). The capture limit is now part size x parts and travels on TranslationSessionRequest, so the watcher, CapturePolicy and TranslationSession agree for that capture. TranslationStreaming gained an optional per-part callback; the session emits chunkStarted and the panel shows 'Part 2 of 4' while streaming and '2 parts' when finished. textTooLong now points at Settings and offers an Open Settings button. Lower the dense-script part-size maximum to 4000 because 5000 dense characters plus a 4096-token output can overflow the 8192-token context. Tests cover capture limits, watcher limits, pipeline part callbacks, session events and limits, panel progress, settings clamping and migration. Docs updated: ADR-011, TRANSLATION_OUTPUT, SELECTION_AND_CLIPBOARD, ARCHITECTURE, LANGUAGES and README. Verified: make verify green; live 4355-character German text showed Part 1 of 2, Part 2 of 2 and '2 parts'; with one part the panel showed the too-long message and Open Settings.
26 lines
995 B
Swift
26 lines
995 B
Swift
import SprachmittlerText
|
||
|
||
/// The result of validating a captured text before any translation request.
|
||
public enum CaptureValidation: Sendable, Equatable {
|
||
/// The text may be translated.
|
||
case valid
|
||
/// The text has no non-whitespace character.
|
||
case empty
|
||
/// The text exceeds the script-aware limit.
|
||
case textTooLong(characters: Int, limit: Int)
|
||
}
|
||
|
||
/// Applies the capture rules shared by double copy, the menu and Services.
|
||
public enum CapturePolicy {
|
||
/// Validates non-emptiness and the capture limit (`chunk size × maximum parts`).
|
||
public static func validate(_ text: String, limits: CaptureLimits = CaptureLimits()) -> CaptureValidation {
|
||
guard text.contains(where: { !$0.isWhitespace }) else { return .empty }
|
||
let limit = limits.captureLimit(for: text)
|
||
let characters = text.count
|
||
guard characters <= limit else {
|
||
return .textTooLong(characters: characters, limit: limit)
|
||
}
|
||
return .valid
|
||
}
|
||
}
|