Commit 2d3da68f4e

2d3da68f4efd780efef41b819fae84407ab95a40

parent: 517b88c774

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-11 03:03 UTC

iOS: redraw only the blocks when the band widens

viewResized() laid the whole file out again whenever the block band's
width changed. In truncate mode the content width grows on each layout
pass that meets a wider line, so scrolling a truncated file relaid out
the whole document repeatedly and moved the text under the view, the
same way fold changes did before invalidateLayout(lines:).

Only shaded block fragments read the band's width, so a band change now
redraws the shaded ranges alone, through redraw(blocks:), extracted from
redrawSelectedBlocks(). A change to the view's own width (rotation,
split view) still lays out the whole file, inside keepingTopLine.

AgendaScreen: drop @retroactive on the Identifiable conformance of
AgendaItem, a same-package type; Xcode 27 rejects it and the target did
not build.

Layout: unified · split

Sources/OrgstarMobile/AgendaScreen.swift +1 −1
@@ -846,7 +846,7 @@ struct DateSheet: View {
846846 }
847847}
848848
849extension AgendaItem: @retroactive Identifiable {
849extension AgendaItem: Identifiable {
850850 public var id: String { "\(path ?? "")|\(headingOffset ?? -1)|\(kind.rawValue)|\(text)" }
851851
852852 /// An entry, not a time-grid line.
Sources/OrgstarMobile/MobileEditor.swift +21 −8
@@ -548,13 +548,18 @@ final class MobileEditor: NSObject, DocumentBuffer {
548548 let range = selected.length > 0 ? selected.location..<NSMaxRange(selected) : nil
549549 let old = fragmentStyle.selection?.range
550550 fragmentStyle.set(selection: range, color: selectionColor)
551 guard let manager = textView.textLayoutManager, let content = manager.textContentManager else { return }
552551 let touched = [old, range].compactMap { $0 }
553 for block in shaded.all where touched.contains(where: { $0.overlaps(block) }) {
552 redraw(blocks: shaded.all.filter { block in touched.contains { $0.overlaps(block) } })
553 }
554
555 /// Lays `blocks` out again and asks their fragments, which are kept across layout passes,
556 /// to draw again.
557 private func redraw(blocks: [Range<Int>]) {
558 guard let manager = textView.textLayoutManager, let content = manager.textContentManager else { return }
559 for block in blocks {
554560 guard let start = content.location(content.documentRange.location, offsetBy: block.lowerBound),
555561 let end = content.location(start, offsetBy: block.count),
556562 let textRange = NSTextRange(location: start, end: end) else { continue }
557 // Fragments are kept across layout passes, so they are asked to draw again too.
558563 manager.invalidateRenderingAttributes(for: textRange)
559564 manager.invalidateLayout(for: textRange)
560565 }
@@ -562,7 +567,9 @@ final class MobileEditor: NSObject, DocumentBuffer {
562567 }
563568
564569 /// The band behind blocks spans the view's width, or the widest line's when truncated;
565 /// images are as wide as the view allows.
570 /// images are as wide as the view allows. Only the blocks read the band's width, so a
571 /// wider line in a truncated file, which widens the band on each layout pass, redraws
572 /// the blocks alone: laying the whole file out again moves the text under the view.
566573 private func viewResized() {
567574 let band = fragmentStyle.blockBand
568575 let width = max(textView.bounds.width, truncatesLines ? textView.contentSize.width : 0)
@@ -570,10 +577,16 @@ final class MobileEditor: NSObject, DocumentBuffer {
570577 guard band.width != width || resized else { return }
571578 fragmentStyle.set(blockBackground: band.color, width: width)
572579 imageWidth = textView.bounds.width
573 if showsImages, resized { restyle(0..<textView.textStorage.length) }
574 if let manager = textView.textLayoutManager {
575 manager.invalidateRenderingAttributes(for: manager.documentRange)
576 manager.invalidateLayout(for: manager.documentRange)
580 guard resized else {
581 redraw(blocks: shaded.all)
582 return
583 }
584 keepingTopLine {
585 if showsImages { restyle(0..<textView.textStorage.length) }
586 if let manager = textView.textLayoutManager {
587 manager.invalidateRenderingAttributes(for: manager.documentRange)
588 manager.invalidateLayout(for: manager.documentRange)
589 }
577590 }
578591 }
579592