Open source CapCut alternative.
TypeScript
feat(app): arrow-key navigation in the expanded notch
David Le4fe97cbd05cb
diff --git a/apps/Donkey/Sources/Donkey/UserQueryOverlayController.swift b/apps/Donkey/Sources/Donkey/UserQueryOverlayController.swiftindex 9bb47dd4..c94bce0b 100644--- a/apps/Donkey/Sources/Donkey/UserQueryOverlayController.swift+++ b/apps/Donkey/Sources/Donkey/UserQueryOverlayController.swift@@ -191,6 +191,13 @@ final class UserQueryOverlayController {panel.mouseDownHandler = { [weak self] inself?.focusStatusComposerTextInputIfAvailable()}+ panel.escapeKeyHandler = { [weak self] in+ // Esc leaves the focused row the same way clicking bare chrome does: highlight and reply clear.+ self?.model.focusNotchRow(nil)+ }+ panel.arrowKeyHandler = { [weak self] direction in+ self?.handleNotchArrowKey(direction) ?? false+ }panel.level = DonkeyOverlayWindowLevel.userQuerypanel.collectionBehavior = [.canJoinAllSpaces,@@ -589,6 +596,7 @@ final class UserQueryOverlayController {spawnStates: model.spawnStates,selectedSpawnID: model.selectedSpawnID,replyTargetTaskID: model.replyTargetTaskID,+ selectedTaskID: model.selectedTaskID,needsLogin: model.needsLogin)}@@ -617,6 +625,7 @@ final class UserQueryOverlayController {tasks: model.notchTasks,surfacedTasks: model.notchSurfacedTasks,replyTargetTaskID: model.replyTargetTaskID,+ selectedTaskID: model.selectedTaskID,accentIndex: model.notchAccentIndex,spawnState: spawnCue,commandSubmitted: { [weak self] text in@@ -645,11 +654,12 @@ final class UserQueryOverlayController {},replyRequested: { [weak self] taskID inguard let self else { return }- self.model.beginReply(toTaskID: taskID)+ // A click focuses the row exactly as arrowing onto it does: highlight + pinned reply.+ self.model.focusNotchRow(taskID)self.focusStatusComposerTextInputIfAvailable()},replyModeExited: { [weak self] in- self?.model.cancelReply()+ self?.model.focusNotchRow(nil)},approvePermissionRequested: { [weak self] taskID, alwaysAllow inself?.model.approvePermissionGate(id: taskID, alwaysAllow: alwaysAllow)@@ -667,6 +677,16 @@ final class UserQueryOverlayController {)}+ /// Up/Down moves the expanded-notch focus, landing on each row exactly as a click would (highlight ++ /// pinned reply, other rows dimmed). Consumed (returns true) only while the notch is open and the+ /// model actually moved the focus; otherwise the arrows fall through to the composer to edit the draft.+ private func handleNotchArrowKey(_ direction: NotchArrowDirection) -> Bool {+ guard isStatusExpanded else { return false }+ let moved = model.moveNotchSelection(direction)+ if moved { updateStatusPanelView() }+ return moved+ }+private func notchSpawnCue(metrics: NotchMetrics) -> UserQuerySpawnState? {spawnOverlayController.cueState(for: model.notchSpawnCue,@@ -820,6 +840,7 @@ final class UserQueryOverlayController {// host stays expanded so it keeps containing the shrinking surface; it snaps to the notch// size once the surface has finished collapsing, when the host shrink fires below.isStatusExpanded = false+ model.clearNotchSelection()updateStatusPanelView()}@@ -1374,6 +1395,9 @@ private final class UserQueryPanel: NSPanel {var dragRegionProvider: (() -> [CGRect])?var escapeKeyHandler: (() -> Void)?var mouseDownHandler: (() -> Void)?+ /// Up/Down arrow handler for the expanded notch. Returns whether it consumed the key; when it does+ /// not (the composer owns the arrows for text editing), the event falls through to the field.+ var arrowKeyHandler: ((NotchArrowDirection) -> Bool)?override var canBecomeKey: Bool {true@@ -1408,6 +1432,17 @@ private final class UserQueryPanel: NSPanel {}override func sendEvent(_ event: NSEvent) {+ if event.type == .keyDown {+ switch Int(event.keyCode) {+ case kVK_UpArrow:+ if arrowKeyHandler?(.up) == true { return }+ case kVK_DownArrow:+ if arrowKeyHandler?(.down) == true { return }+ default:+ break+ }+ }+if event.type == .keyDown,event.keyCode == UInt16(kVK_Escape) {escapeKeyHandler?()@@ -1461,6 +1496,7 @@ private struct StatusPanelViewSnapshot: Equatable {var spawnStates: [UserQuerySpawnState]var selectedSpawnID: String?var replyTargetTaskID: String?+ var selectedTaskID: String?var needsLogin: Bool}diff --git a/apps/Donkey/Sources/Donkey/UserQueryOverlayModel.swift b/apps/Donkey/Sources/Donkey/UserQueryOverlayModel.swiftindex 1efd8500..13f34f77 100644--- a/apps/Donkey/Sources/Donkey/UserQueryOverlayModel.swift+++ b/apps/Donkey/Sources/Donkey/UserQueryOverlayModel.swift@@ -20,7 +20,7 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {@Published var notchCommandText = "" {didSet {// Starting a draft hands the arrows back to the composer for text editing; the row- // highlight re-engages when the user clicks a row (see `setNotchSelection`).+ // highlight re-engages when the user clicks or arrows onto a row (see `focusNotchRow`).if !notchCommandText.isEmpty { selectedTaskID = nil }}}@@ -735,57 +735,44 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {}}- /// The user tapped Reply on a task that is waiting on them (a clarification or a review). Pin the- /// next composer submission to that task so the answer continues it rather than starting a new task- /// or being matched elsewhere by the resolver; the controller focuses the input after this.- func beginReply(toTaskID taskID: String) {- // Any existing thread is repliable, whatever its state — running/permission-gated threads take- // the message as a queued follow-up downstream, the rest resume.- guard task(withID: taskID) != nil else {- return- }- // Tapping Reply on the row already targeted cancels reply mode and un-dims the other rows, so the- // user is never stuck in a dimmed state with no way back out short of sending a message.- if replyTargetTaskID == taskID {- replyTargetTaskID = nil- return- }- replyTargetTaskID = taskID- lastActiveTaskID = taskID- }-- /// Leave reply mode without sending — the user tapped elsewhere in the notch chrome. No-op when no- /// reply is targeted, so a stray background tap in normal use does nothing.- func cancelReply() {- guard replyTargetTaskID != nil else { return }- replyTargetTaskID = nil- }-- /// Move the expanded-notch keyboard highlight. The rows and the composer form one vertical cycle- /// (rows top-to-bottom, composer at the bottom) that Up/Down step through and wrap around. Returns- /// whether the key was consumed: at the composer with a draft already typed, the arrows fall through- /// so they edit the text instead of moving the highlight.+ /// Move the expanded-notch focus with the arrows. With a row already focused, Up/Down step through the+ /// rows and clamp at the ends — reaching the top or bottom holds that row rather than dropping back to+ /// the composer — so the selection is never lost mid-navigation. With nothing focused the arrows enter+ /// the list (Up at the bottom row nearest the composer, Down at the top); landing on a row does exactly+ /// what clicking it does (highlight + pinned reply, other rows dim). Returns whether the key was+ /// consumed; at the composer with a draft already typed, the arrows fall through to edit the text.@discardableResultfunc moveNotchSelection(_ direction: NotchArrowDirection) -> Bool {guard !notchTasks.isEmpty else { return false }- let composerSlot = notchTasks.count- let total = composerSlot + 1- let current = selectedTaskID- .flatMap { id in notchTasks.firstIndex { $0.id == id } } ?? composerSlot- // At the composer with text already in progress, the arrows belong to the draft, not the list.- if current == composerSlot, !notchCommandText.isEmpty { return false }+ let lastIndex = notchTasks.count - 1+ guard let current = selectedTaskID.flatMap({ id in notchTasks.firstIndex { $0.id == id } }) else {+ // No row focused yet: enter the list, but only when the composer isn't holding a draft.+ if !notchCommandText.isEmpty { return false }+ let entry = direction == .up ? lastIndex : 0+ focusNotchRow(notchTasks[entry].id)+ return true+ }let next: Intswitch direction {- case .up: next = (current - 1 + total) % total- case .down: next = (current + 1) % total+ case .up: next = max(0, current - 1)+ case .down: next = min(lastIndex, current + 1)}- selectedTaskID = next == composerSlot ? nil : notchTasks[next].id+ focusNotchRow(notchTasks[next].id)return true}- /// Engage the row highlight directly (a row click) so arrow navigation resumes from that row.- func setNotchSelection(_ taskID: String?) {+ /// Make `taskID` the focused thread — the shared effect of clicking a row and of arrowing onto it: it+ /// becomes the keyboard highlight and the reply target (its pointer lights, the composer takes its+ /// accent, and the other rows dim). Passing nil (Escape, or leaving reply) clears both, the same as+ /// clicking bare chrome.+ func focusNotchRow(_ taskID: String?) {selectedTaskID = taskID+ guard let taskID, task(withID: taskID) != nil else {+ replyTargetTaskID = nil+ return+ }+ replyTargetTaskID = taskID+ lastActiveTaskID = taskID}func clearNotchSelection() {diff --git a/apps/Donkey/Sources/DonkeyUI/UserQueryNotchStatusView.swift b/apps/Donkey/Sources/DonkeyUI/UserQueryNotchStatusView.swiftindex 6b505314..4618692d 100644--- a/apps/Donkey/Sources/DonkeyUI/UserQueryNotchStatusView.swift+++ b/apps/Donkey/Sources/DonkeyUI/UserQueryNotchStatusView.swift@@ -31,6 +31,9 @@ public struct UserQueryNotchStatusView: View {/// While the user is replying to a specific task (tapped Reply), this is that task; the expanded/// panel dims every other row so it's clear the next message continues this one thread.private let replyTargetTaskID: String?+ /// The row the keyboard arrows currently highlight (distinct from the reply target). It renders a+ /// brighter fill and a ring so the selection reads while the composer keeps text focus.+ private let selectedTaskID: String?private let accentIndex: Intprivate let spawnState: UserQuerySpawnState?private let commandSubmitted: @MainActor (String) -> Void@@ -71,6 +74,7 @@ public struct UserQueryNotchStatusView: View {tasks: [UserQueryNotchTask] = [],surfacedTasks: [UserQueryNotchTask] = [],replyTargetTaskID: String? = nil,+ selectedTaskID: String? = nil,accentIndex: Int,spawnState: UserQuerySpawnState? = nil,commandSubmitted: @escaping @MainActor (String) -> Void,@@ -103,6 +107,7 @@ public struct UserQueryNotchStatusView: View {self.tasks = tasksself.surfacedTasks = surfacedTasksself.replyTargetTaskID = replyTargetTaskID+ self.selectedTaskID = selectedTaskIDself.accentIndex = accentIndexself.spawnState = spawnStateself.commandSubmitted = commandSubmitted@@ -502,21 +507,31 @@ public struct UserQueryNotchStatusView: View {}VStack(spacing: Self.taskListCommandSpacing) {- ScrollView(.vertical, showsIndicators: false) {- VStack(spacing: 8) {- if tasks.isEmpty {- currentTaskRow- } else {- ForEach(tasks) { task in- // While replying to one task, the others dim back (handled inside the row- // so an attention pointer can stay lit) — it's clear which thread the next- // message continues.- taskRow(task)- .animation(.easeOut(duration: 0.16), value: replyTargetTaskID)+ ScrollViewReader { proxy in+ ScrollView(.vertical, showsIndicators: false) {+ VStack(spacing: 8) {+ if tasks.isEmpty {+ currentTaskRow+ } else {+ ForEach(tasks) { task in+ // While replying to one task, the others dim back (handled inside the+ // row so an attention pointer can stay lit) — it's clear which thread+ // the next message continues.+ taskRow(task)+ .id(task.id)+ .animation(.easeOut(duration: 0.16), value: replyTargetTaskID)+ }}}+ .padding(.top, 10)+ }+ // Keep the keyboard-highlighted row on screen as the arrows walk past the fold.+ .onChange(of: selectedTaskID) {+ guard let selectedTaskID else { return }+ withAnimation(.easeOut(duration: 0.16)) {+ proxy.scrollTo(selectedTaskID, anchor: .center)+ }}- .padding(.top, 10)}commandRow@@ -780,15 +795,16 @@ public struct UserQueryNotchStatusView: View {// itself needs the user can stay lit while everything else recedes.let contentDim = rowReplyDimOpacity(for: task)let isReplyTarget = replyTargetTaskID == task.id- let pointerDim = isWaitingForReply(task) ? 1 : contentDim+ let isSelected = selectedTaskID == task.id+ let pointerDim = (isWaitingForReply(task) || isSelected) ? 1 : contentDimreturn VStack(alignment: .leading, spacing: 8) {HStack(alignment: .top, spacing: 12) {// Colored pointer while actively running; silhouette once stopped or finished — but the- // reply target always shows its live accent color, so even a finished thread reads as- // active again while the user is replying to it.+ // reply target and the keyboard-highlighted row always show their live accent color, so+ // even a finished thread reads as active again while it is the focus.DonkeyCursorMark(color: accentColor(for: task.accentIndex),- silhouette: !isReplyTarget && task.status != .running+ silhouette: !isReplyTarget && !isSelected && task.status != .running).frame(width: 14, height: 14).padding(.top, 1)@@ -835,10 +851,18 @@ public struct UserQueryNotchStatusView: View {// row renders at the same height and places the time identically; only genuinely long detail// grows past it (and never crowds the time)..frame(minHeight: 72)- // The cell fill recedes with the rest of the content while a reply targets another row.- .background(Color.white.opacity(0.07 * contentDim))+ // The cell fill recedes with the rest of the content while a reply targets another row; a+ // keyboard-highlighted row instead brightens to full strength so the selection reads clearly.+ .background(Color.white.opacity(isSelected ? 0.16 : 0.07 * contentDim)).clipShape(RoundedRectangle(cornerRadius: 8, style: .continuous))+ .overlay {+ if isSelected {+ RoundedRectangle(cornerRadius: 8, style: .continuous)+ .strokeBorder(Color.white.opacity(0.3), lineWidth: 1)+ }+ }.contentShape(RoundedRectangle(cornerRadius: 8, style: .continuous))+ .animation(.easeOut(duration: 0.12), value: isSelected).onTapGesture {// Every row is repliable. Tapping the active thread again leaves reply mode; tapping any// other row pins it and focuses the composer, so the user can just start typing. (A running@@ -1045,6 +1069,17 @@ public struct UserQueryNotchStatusView: View {return accentColor(for: task.accentIndex)}+ /// The composer's outline color. The keyboard-highlighted row takes precedence — its accent rides on+ /// the input so the selection reads as the next thread the user will reply to — and falls back to the+ /// reply target's accent while one is pinned.+ private var composerAccentColor: Color? {+ if let selectedTaskID,+ let task = tasks.first(where: { $0.id == selectedTaskID }) {+ return accentColor(for: task.accentIndex)+ }+ return replyTargetAccentColor+ }+private var commandRow: some View {UserQueryComposer(state: commandInputState,@@ -1052,7 +1087,7 @@ public struct UserQueryNotchStatusView: View {inputTextHeight: commandInputTextHeight,isInputExpanded: isCommandInputExpanded,surfaceFill: Color.white.opacity(0.085),- borderColor: replyTargetAccentColor,+ borderColor: composerAccentColor,forceExpandedSurface: true,toolbarStyle: .followUp,sizeProfile: .compact,