Skip to content

知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.

fix: Keep the live transcript where you scrolled it on macOS 14 instead of jumping to the newest line

wquguruba8569674b73
diff --git a/Sources/LiveSubs/Compat.swift b/Sources/LiveSubs/Compat.swift
index 3f47c1f..823a22b 100644
--- a/Sources/LiveSubs/Compat.swift
+++ b/Sources/LiveSubs/Compat.swift
@@ -12,8 +12,8 @@ extension View {
}
}
- /// Where a scroll view's content sits against its bottom edge. macOS 14 doesn't report it:
- /// there the transcript keeps following new lines even after the reader scrolls up.
+ /// Where a scroll view's content sits against its bottom edge (15 and later; 14 has
+ /// `onLegacyBottomDistance` below).
@ViewBuilder func onScrollEdgeChange(_ action: @escaping (ScrollEdge, ScrollEdge) -> Void) -> some View {
if #available(macOS 15, *) {
onScrollGeometryChange(for: ScrollEdge.self) { g in
@@ -35,6 +35,52 @@ extension View {
}
}
+extension View {
+ /// macOS 14: how far `bottomMarker` (the content's last view) is below the visible area,
+ /// measured by geometry since `onScrollGeometryChange` is 15 and later. Does nothing on 15+.
+ @ViewBuilder func onLegacyBottomDistance(_ action: @escaping (CGFloat) -> Void) -> some View {
+ if #available(macOS 15, *) {
+ self
+ } else {
+ coordinateSpace(name: LegacyScrollEdge.space)
+ .background(GeometryReader { g in
+ Color.clear.preference(key: LegacyScrollEdge.Container.self, value: g.size.height)
+ })
+ .onPreferenceChange(LegacyScrollEdge.Container.self) { LegacyScrollEdge.container = $0 }
+ // The lazy stack doesn't draw a marker scrolled far out of view: that's far from the bottom.
+ .onPreferenceChange(LegacyScrollEdge.Bottom.self) { y in
+ action(y < 0 ? .greatestFiniteMagnitude : y - LegacyScrollEdge.container)
+ }
+ }
+ }
+
+ /// Put on the content's last view (macOS 14, with `onLegacyBottomDistance` on the scroll view).
+ @ViewBuilder func bottomMarker() -> some View {
+ if #available(macOS 15, *) {
+ self
+ } else {
+ background(GeometryReader { g in
+ Color.clear.preference(key: LegacyScrollEdge.Bottom.self,
+ value: g.frame(in: .named(LegacyScrollEdge.space)).maxY)
+ })
+ }
+ }
+}
+
+enum LegacyScrollEdge {
+ static let space = "cicada.scroll"
+ nonisolated(unsafe) static var container: CGFloat = 0
+ struct Container: PreferenceKey {
+ static let defaultValue: CGFloat = 0
+ static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) { value = max(value, nextValue()) }
+ }
+ /// -1 while the marker isn't drawn.
+ struct Bottom: PreferenceKey {
+ static let defaultValue: CGFloat = -1
+ static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) { value = max(value, nextValue()) }
+ }
+}
+
/// How far the content's bottom is below the visible area, the content's height and the view's.
struct ScrollEdge: Equatable {
var distance: CGFloat
diff --git a/Sources/LiveSubs/NotesViews.swift b/Sources/LiveSubs/NotesViews.swift
index e4be49e..61517ef 100644
--- a/Sources/LiveSubs/NotesViews.swift
+++ b/Sources/LiveSubs/NotesViews.swift
@@ -619,10 +619,20 @@ struct TranscriptListView<Partial: View>: View, Equatable {
.frame(maxWidth: .infinity).padding(.top, 40)
}
}
- Color.clear.frame(height: 1).id("bottom")
+ Color.clear.frame(height: 1).id("bottom").bottomMarker()
}
.padding(.top, 8).padding(.bottom, 12)
}
+ .onLegacyBottomDistance { distance in
+ // macOS 14: only the reader's own scrolling changes following; anything else that
+ // moves the bottom (new lines, translations, resizing) is followed.
+ if UserScroll.recent {
+ if distance < 40 { if !following { following = true } }
+ else if following, distance > 60 { following = false; seenCount = lines.count }
+ } else if following, distance > 1 {
+ follow(proxy)
+ }
+ }
.topFade()
.onScrollEdgeChange { old, new in
if new.height != old.height || new.container != old.container {