Skip to content

Open source CapCut alternative.

TypeScript

Cycle pointer prompt accents

David Le524d410ee307
diff --git a/apps/Donkey/Sources/Donkey/PointerPromptOverlayModel.swift b/apps/Donkey/Sources/Donkey/PointerPromptOverlayModel.swift
index 7e59be44..9d82c5a4 100644
--- a/apps/Donkey/Sources/Donkey/PointerPromptOverlayModel.swift
+++ b/apps/Donkey/Sources/Donkey/PointerPromptOverlayModel.swift
@@ -54,6 +54,8 @@ final class PointerPromptOverlayModel: ObservableObject, PointerPromptIntentSink
self.documentReviewController = documentReviewController
let restoredTasks = Self.restoredTasks(from: taskStore.loadRecentTasks(limit: Self.notchTaskDisplayLimit))
notchTasks = restoredTasks
+ notchAccentIndex = restoredTasks.first.map { PointerPromptAccentPalette.normalizedIndex($0.accentIndex) }
+ ?? PointerPromptAccentPalette.firstIndex
isCurrentTaskPaused = restoredTasks.first?.status == .paused
updateState = PointerPromptUpdateState(
currentVersion: updateChecker.currentVersion
@@ -296,7 +298,12 @@ final class PointerPromptOverlayModel: ObservableObject, PointerPromptIntentSink
spawnID: String? = nil
) {
let isFollowUp = matchedTaskID != nil
- let task = taskForSubmittedCommand(text: text, matchedTaskID: matchedTaskID)
+ let reservedAccentIndex = spawnID.flatMap { spawn(withID: $0)?.accentIndex }
+ let task = taskForSubmittedCommand(
+ text: text,
+ matchedTaskID: matchedTaskID,
+ reservedAccentIndex: reservedAccentIndex
+ )
updateSpawn(
id: spawnID,
taskID: task.id,
@@ -409,12 +416,19 @@ final class PointerPromptOverlayModel: ObservableObject, PointerPromptIntentSink
let spawnID = UUID().uuidString
let displayText = Self.taskLabel(for: text)
let labelText = label ?? Self.collapsedDisplayText(for: text)
+ let spawnAccentIndex: Int
+ if let accentIndex {
+ spawnAccentIndex = PointerPromptAccentPalette.normalizedIndex(accentIndex)
+ } else {
+ spawnAccentIndex = nextRoundRobinAccentIndex()
+ }
+ notchAccentIndex = spawnAccentIndex
let spawnState = PointerPromptSpawnState(
id: spawnID,
taskID: taskID,
commandText: text,
label: labelText,
- accentIndex: accentIndex ?? Self.nextAccentIndex(after: notchAccentIndex),
+ accentIndex: spawnAccentIndex,
phase: .notchCue
)
spawnStates.append(spawnState)
@@ -573,18 +587,24 @@ final class PointerPromptOverlayModel: ObservableObject, PointerPromptIntentSink
promptState.isVoiceInputActive = false
}
- private func taskForSubmittedCommand(text: String, matchedTaskID: String?) -> PointerPromptNotchTask {
+ private func taskForSubmittedCommand(
+ text: String,
+ matchedTaskID: String?,
+ reservedAccentIndex: Int? = nil
+ ) -> PointerPromptNotchTask {
if let matchedTaskID,
var task = task(withID: matchedTaskID) {
task.detail = "Running"
task.status = .running
task.updatedAt = Date()
+ notchAccentIndex = PointerPromptAccentPalette.normalizedIndex(task.accentIndex)
prependTask(task)
return task
}
let taskLabel = Self.taskLabel(for: text)
- let nextAccentIndex = Self.nextAccentIndex(after: notchAccentIndex)
+ let nextAccentIndex = reservedAccentIndex.map(PointerPromptAccentPalette.normalizedIndex)
+ ?? nextRoundRobinAccentIndex()
notchAccentIndex = nextAccentIndex
let task = PointerPromptNotchTask(
id: UUID().uuidString,
@@ -613,7 +633,7 @@ final class PointerPromptOverlayModel: ObservableObject, PointerPromptIntentSink
return recentTask
}
- let nextAccentIndex = Self.nextAccentIndex(after: notchAccentIndex)
+ let nextAccentIndex = nextRoundRobinAccentIndex()
notchAccentIndex = nextAccentIndex
let task = PointerPromptNotchTask(
id: UUID().uuidString,
@@ -820,9 +840,12 @@ final class PointerPromptOverlayModel: ObservableObject, PointerPromptIntentSink
}
}
- private static func nextAccentIndex(after currentIndex: Int) -> Int {
- let accentCount = 8
- return (currentIndex + 1) % accentCount
+ private func nextRoundRobinAccentIndex() -> Int {
+ guard let mostRecentAccentIndex = spawnStates.last?.accentIndex ?? notchTasks.first?.accentIndex else {
+ return PointerPromptAccentPalette.firstIndex
+ }
+
+ return PointerPromptAccentPalette.index(after: mostRecentAccentIndex)
}
private static func taskLabel(for text: String) -> String {
diff --git a/apps/Donkey/Sources/DonkeyContracts/PointerPromptAccentPalette.swift b/apps/Donkey/Sources/DonkeyContracts/PointerPromptAccentPalette.swift
new file mode 100644
index 00000000..942ec23a
--- /dev/null
+++ b/apps/Donkey/Sources/DonkeyContracts/PointerPromptAccentPalette.swift
@@ -0,0 +1,12 @@
+public enum PointerPromptAccentPalette {
+ public static let supportedIndexes = [0, 1, 2, 3, 4, 5, 6, 7]
+ public static let firstIndex = supportedIndexes[0]
+
+ public static func normalizedIndex(_ index: Int) -> Int {
+ supportedIndexes[((index % supportedIndexes.count) + supportedIndexes.count) % supportedIndexes.count]
+ }
+
+ public static func index(after index: Int) -> Int {
+ normalizedIndex(index + 1)
+ }
+}
diff --git a/apps/Donkey/Sources/DonkeyUI/PointerPromptNotchStatusView.swift b/apps/Donkey/Sources/DonkeyUI/PointerPromptNotchStatusView.swift
index d7393706..603235e0 100644
--- a/apps/Donkey/Sources/DonkeyUI/PointerPromptNotchStatusView.swift
+++ b/apps/Donkey/Sources/DonkeyUI/PointerPromptNotchStatusView.swift
@@ -790,7 +790,7 @@ public struct PointerPromptNotchStatusView: View {
}
private func accentColor(for index: Int) -> Color {
- Self.accentColors[((index % Self.accentColors.count) + Self.accentColors.count) % Self.accentColors.count]
+ Self.accentColors[PointerPromptAccentPalette.normalizedIndex(index)]
}
private static let accentColors: [Color] = [
diff --git a/apps/Donkey/Sources/DonkeyUI/PointerPromptSpawnOverlayView.swift b/apps/Donkey/Sources/DonkeyUI/PointerPromptSpawnOverlayView.swift
index 8c1f734a..5b79d874 100644
--- a/apps/Donkey/Sources/DonkeyUI/PointerPromptSpawnOverlayView.swift
+++ b/apps/Donkey/Sources/DonkeyUI/PointerPromptSpawnOverlayView.swift
@@ -662,11 +662,11 @@ public struct PointerPromptSpawnOverlayView: View {
}
private func accentColor(for index: Int) -> Color {
- Self.accentColors[((index % Self.accentColors.count) + Self.accentColors.count) % Self.accentColors.count]
+ Self.accentColors[PointerPromptAccentPalette.normalizedIndex(index)]
}
private func inputAccentColor(for index: Int) -> Color {
- Self.inputAccentColors[((index % Self.inputAccentColors.count) + Self.inputAccentColors.count) % Self.inputAccentColors.count]
+ Self.inputAccentColors[PointerPromptAccentPalette.normalizedIndex(index)]
}
private static let accentColors: [Color] = [
diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/PointerPromptAccentPaletteTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/PointerPromptAccentPaletteTests.swift
new file mode 100644
index 00000000..f8f410e9
--- /dev/null
+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/PointerPromptAccentPaletteTests.swift
@@ -0,0 +1,32 @@
+import DonkeyContracts
+import Testing
+
+@Suite
+struct PointerPromptAccentPaletteTests {
+ @Test
+ func paletteCyclesThroughSupportedAccentList() {
+ var currentIndex: Int?
+
+ let sequence = (0..<10).map { _ in
+ let nextIndex = currentIndex.map(PointerPromptAccentPalette.index(after:))
+ ?? PointerPromptAccentPalette.firstIndex
+ currentIndex = nextIndex
+ return nextIndex
+ }
+
+ #expect(sequence == [0, 1, 2, 3, 4, 5, 6, 7, 0, 1])
+ }
+
+ @Test
+ func paletteContinuesAfterKnownAccent() {
+ #expect(PointerPromptAccentPalette.index(after: 1) == 2)
+ #expect(PointerPromptAccentPalette.index(after: 7) == 0)
+ }
+
+ @Test
+ func paletteNormalizesOutOfRangeIndexes() {
+ #expect(PointerPromptAccentPalette.normalizedIndex(-1) == 7)
+ #expect(PointerPromptAccentPalette.normalizedIndex(8) == 0)
+ #expect(PointerPromptAccentPalette.index(after: 7) == 0)
+ }
+}