fix(ui): finish-audit fixes — blank search glyph, quadratic truncation, scope-rail refusal leak
CI / ci (push) Canceled after 0s
CI / ci (pull_request) Canceled after 0s
CI / ci (push) Canceled after 0s
CI / ci (pull_request) Canceled after 0s
Three-reviewer audit of the polish overhaul: - magnifyinglass -> magnifyingglass (blank SF Symbol, all 3 seats) - WordBoundaryTruncation.fit measures each word once (O(n^2) -> O(n) on pathological imported titles; live-title pins unchanged) - scopeHostedSession defers behind an in-flight replay instead of refusing (automatic actions never leak a 'Resume refused' row); replay completion re-fires the pending scope — pinned over the real client path with loadReplayHold, flip-verified - transcript ForEach on stable row ids, not indices - delete dead softBorder param; fold caretPastLeadingBlanks onto firstContentLocation; native TextField prompt for the search field - ElidedPathText.candidates/elide nonisolated (off-actor first(where:) trapped the host); new pins: degenerate truncation shapes, firstContentLocation, elide ladder
This commit is contained in:
1 parent
3a7d495b4b
commit
efad422e03
13 files changed
+163
-65
No files matched your search
@@ -522,7 +522,14 @@ nonisolated enum WordBoundaryTruncation {
|
||||
/// (lineLimit catches it).
|
||||
static func fit(_ text: String, maxWidth: CGFloat, lines: Int = 2) -> String {
|
||||
let words = text.split(separator: " ", omittingEmptySubsequences: true).map(String.init)
|
||||
guard !words.isEmpty, lineCount(words, maxWidth) > lines else { return text }
|
||||
guard !words.isEmpty else { return text }
|
||||
// Finish-audit: measure each word ONCE — a pathological title (an
|
||||
// imported post's first line is unbounded) must not turn the
|
||||
// candidate loop into quadratic glyph measurement on the main actor.
|
||||
// ponytail: one pass per word is fine to ~10k words; bail to native
|
||||
// lineLimit if a roster row ever renders slower than a frame.
|
||||
let widths = words.map { width($0) }
|
||||
guard lineCount(widths, maxWidth) > lines else { return text }
|
||||
var head = [words[0]]
|
||||
if words.count > 2, words[2] == "·" {
|
||||
head = [words[0], words[1], words[2]]
|
||||
@@ -537,22 +544,24 @@ nonisolated enum WordBoundaryTruncation {
|
||||
index += 1
|
||||
}
|
||||
let tail = Array(words.dropFirst(head.count))
|
||||
let ellipsis = width("…")
|
||||
let headWidths = Array(widths[0 ..< head.count])
|
||||
for count in stride(from: tail.count, through: 1, by: -1) {
|
||||
let candidate = head.joined(separator: " ") + " … " + tail.suffix(count).joined(separator: " ")
|
||||
if lineCount(candidate.split(separator: " ").map(String.init), maxWidth) <= lines {
|
||||
return candidate
|
||||
let candidateWidths = headWidths + [ellipsis] + Array(widths[(words.count - count)...])
|
||||
if lineCount(candidateWidths, maxWidth) <= lines {
|
||||
return head.joined(separator: " ") + " … " + tail.suffix(count).joined(separator: " ")
|
||||
}
|
||||
}
|
||||
return head.joined(separator: " ") + "…"
|
||||
}
|
||||
|
||||
/// Greedy word wrap (the text system's own algorithm): how many
|
||||
/// lines `words` need at `maxWidth`.
|
||||
private static func lineCount(_ words: [String], _ maxWidth: CGFloat) -> Int {
|
||||
/// lines `widths` (per-word glyph widths, measured once) need at
|
||||
/// `maxWidth`.
|
||||
private static func lineCount(_ widths: [CGFloat], _ maxWidth: CGFloat) -> Int {
|
||||
var lines = 1
|
||||
var used: CGFloat = 0
|
||||
for word in words {
|
||||
let tokenWidth = width(word)
|
||||
for tokenWidth in widths {
|
||||
if used == 0 {
|
||||
// A word wider than the line keeps its own line — the
|
||||
// mid-word break is SwiftUI's, never the seam's.
|
||||
|
||||
Reference in new issue
Block a user