Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(timeline): select text on the first click (#6463)

Louis Beaumontddcbb9ca02bd
diff --git a/apps/screenpipe-app-tauri/src-tauri/swift/timeline/TimelineLiveText.swift b/apps/screenpipe-app-tauri/src-tauri/swift/timeline/TimelineLiveText.swift
index 2d1286f36..bd4237ea5 100644
--- a/apps/screenpipe-app-tauri/src-tauri/swift/timeline/TimelineLiveText.swift
+++ b/apps/screenpipe-app-tauri/src-tauri/swift/timeline/TimelineLiveText.swift
@@ -94,6 +94,11 @@ final class TimelineLiveTextContainer: NSView {
)
}
+ /// The pointer lands on VisionKit's overlay, not here, so this only
+ /// covers clicks on the frame's margins. `TimelineWindow.sendEvent`
+ /// is what keeps the first selection gesture alive over the text.
+ override func acceptsFirstMouse(for event: NSEvent?) -> Bool { true }
+
override func layout() {
super.layout()
let fitted = Self.aspectFitRect(imageSize: imageView.image?.size ?? .zero, inside: bounds)
diff --git a/apps/screenpipe-app-tauri/src-tauri/swift/timeline/TimelineWindow.swift b/apps/screenpipe-app-tauri/src-tauri/swift/timeline/TimelineWindow.swift
index c5efe74e7..49ff3cf46 100644
--- a/apps/screenpipe-app-tauri/src-tauri/swift/timeline/TimelineWindow.swift
+++ b/apps/screenpipe-app-tauri/src-tauri/swift/timeline/TimelineWindow.swift
@@ -429,6 +429,32 @@ struct TimelineSearchNavigationRequest: Equatable {
final class TimelineWindow: NSWindow {
override var canBecomeKey: Bool { true }
override var canBecomeMain: Bool { false }
+
+ /// The click that focuses an attached timeline must also do its job.
+ ///
+ /// AppKit spends the mouse-down that makes a window key on the activation
+ /// alone, unless the view under the pointer accepts first mouse. Over a
+ /// frame that view is VisionKit's `ImageAnalysisOverlayView`, which is
+ /// `final` — there is no override to add. Taking key before the event is
+ /// dispatched turns it into an ordinary click, so the first drag selects
+ /// text instead of only waking the window up.
+ override func sendEvent(_ event: NSEvent) {
+ if event.type == .leftMouseDown, !isKeyWindow { makeKey() }
+ super.sendEvent(event)
+ }
+}
+
+/// Being able to become key is not the same as becoming key.
+///
+/// Attached mode never makes this window key — the host webview keeps that, so
+/// the timeline does not steal keystrokes the moment it appears. The click that
+/// does make it key is AppKit's "first mouse", and by default a view is not
+/// sent that event: it only activates the window. So the first drag over a
+/// transcript selected nothing, and the user had to click something else first
+/// to wake the window up. Accepting first mouse spends that click on the
+/// gesture as well as the activation.
+final class TimelineHostingView<Content: View>: NSHostingView<Content> {
+ override func acceptsFirstMouse(for event: NSEvent?) -> Bool { true }
}
@MainActor
@@ -759,7 +785,7 @@ final class TimelineWindowController: NSObject, NSWindowDelegate {
model.beginExternalNavigation()
}
- let hosting = NSHostingView(
+ let hosting = TimelineHostingView(
rootView: TimelineHostView(
model: model,
originChrome: originChrome,
diff --git a/apps/screenpipe-app-tauri/src-tauri/swift/timeline_interaction_tests.swift b/apps/screenpipe-app-tauri/src-tauri/swift/timeline_interaction_tests.swift
index bbc54ac00..3840a494d 100644
--- a/apps/screenpipe-app-tauri/src-tauri/swift/timeline_interaction_tests.swift
+++ b/apps/screenpipe-app-tauri/src-tauri/swift/timeline_interaction_tests.swift
@@ -273,6 +273,28 @@ private func testNoOverlaySwallowsHitTests(window: NSWindow) {
}
}
+/// The click that activates the timeline has to do its job too.
+///
+/// An attached timeline is a child window: the host webview keeps key focus, so
+/// the first click over the timeline is AppKit's "first mouse". A view that
+/// declines it spends that event on activation alone, and the user's first drag
+/// over a frame or a transcript selects nothing — they have to click something
+/// else first and try again. Asserted structurally, because a test binary is
+/// never the active app and so cannot be clicked (see the note at the top).
+@MainActor
+private func testFirstMouseReachesContent(window: NSWindow) {
+ expect(window is TimelineWindow,
+ "the timeline must use TimelineWindow, got \(type(of: window))")
+ guard let content = window.contentView else {
+ failures.append("the window has no content view")
+ return
+ }
+ expect(content.acceptsFirstMouse(for: nil),
+ "the SwiftUI host must accept first mouse, or the activating click is swallowed")
+ expect(TimelineLiveTextContainer().acceptsFirstMouse(for: nil),
+ "the frame canvas must accept first mouse")
+}
+
/// Buttons have to actually run their action. Found through accessibility, then
/// pressed the way an assistive client presses them.
@MainActor
@@ -1117,6 +1139,7 @@ private func runTests() {
let groups: [(String, () -> Void)] = [
("idle and hidden lifecycle", { testIdleAndHiddenLifecycle(model: model) }),
("no overlay swallows hit tests", { testNoOverlaySwallowsHitTests(window: window) }),
+ ("first mouse reaches content", { testFirstMouseReachesContent(window: window) }),
("control bar buttons respond",
{ testControlBarButtonsRespond(window: window, model: model) }),
("scrubber is reachable", { testScrubberIsReachable(window: window, model: model) }),