Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -603,13 +603,19 @@ class AccessibilityNotificationsManager: ObservableObject {

screenResult.userInteraction.selectedText = nil
PanelStateCoordinator.shared.state.pendingInput = nil
PanelStateCoordinator.shared.state.trackedPendingInput = nil
return
}

screenResult.userInteraction.selectedText = selectedText

let input = Input(selectedText: selectedText, application: currentSource ?? "")
PanelStateCoordinator.shared.state.pendingInput = input

if Defaults[.autoAddHighlightedTextToContext] {
PanelStateCoordinator.shared.state.pendingInput = input
} else {
PanelStateCoordinator.shared.state.trackedPendingInput = input
}
}

// MARK: Caret Position Handling
Expand Down
2 changes: 2 additions & 0 deletions macos/Onit/Data/Persistence/Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ extension Defaults.Keys {
static let lineHeight = Key<Double>("lineHeight", default: 1.5)
static let voiceSilenceThreshold = Key<Float>("voiceSilenceThreshold", default: -40)
static let voiceSpeechPassThreshold = Key<Double>("voiceSpeechPassThreshold", default: 0.7)
/// Highlighted Text
static let showHighlightedTextInput = Key<Bool>("showHighlightedTextInput", default: true)
static let autoAddHighlightedTextToContext = Key<Bool>("autoAddHighlightedTextToContext", default: true)

// Local model advanced options
static let localKeepAlive = Key<String?>("localKeepAlive", default: nil)
Expand Down
2 changes: 2 additions & 0 deletions macos/Onit/UI/Panels/State/OnitPanelState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ class OnitPanelState: NSObject {
}
}

var trackedPendingInput: Input? = nil

var systemPromptId: String = SystemPrompt.outputOnly.id

var imageUploads: [URL: UploadProgress] = [:]
Expand Down
70 changes: 58 additions & 12 deletions macos/Onit/UI/Prompt/Files/FileRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct FileRow: View {
@ObservedObject private var debugManager = DebugManager.shared

@Default(.autoContextFromCurrentWindow) var autoContextFromCurrentWindow
@Default(.autoAddHighlightedTextToContext) var autoAddHighlightedTextToContext

@State private var ocrComparisonResult: OCRComparisonResult? = nil
@State private var showOCRDetails = false
Expand Down Expand Up @@ -119,7 +120,8 @@ struct FileRow: View {
FlowLayout(spacing: 6) {
PaperclipButton()

addForegroundWindowToContextButton
addHighlightedTextToContextButton
addWindowToContextButton
pendingWindowContextItems
highlightedTextContext
addedWindowContextItems
Expand Down Expand Up @@ -150,28 +152,70 @@ struct FileRow: View {
// MARK: - Child Components

extension FileRow {
private func ghostContextTag(
text: String,
iconBundleURL: URL? = nil,
iconView: (any View)? = nil,
tooltip: String,
action: @escaping () -> Void
) -> some View {
ContextTag(
text: text,
textColor: .T_2,
hoverTextColor: .white,
background: contextTagBackground,
hoverBackground: contextTagHoverBackground,
hasHoverBorder: true,
shouldFadeIn: true,
iconBundleURL: iconBundleURL,
iconView: iconView,
tooltip: tooltip
) {
action()
}
}

@ViewBuilder
private var addHighlightedTextToContextButton: some View {
if accessibilityEnabled,
Defaults[.autoContextFromHighlights],
let windowState = windowState,
let trackedPendingInput = windowState.trackedPendingInput
{
ghostContextTag(
text: trackedPendingInput.selectedText,
iconView: Image(.text).addIconStyles(iconSize: 14),
tooltip: "Add Highlighted Text To Context"
) {
windowState.pendingInput = trackedPendingInput
windowState.trackedPendingInput = nil
}
.onChange(of: autoAddHighlightedTextToContext) { _, autoAddHighlightedText in
if autoAddHighlightedText {
windowState.pendingInput = trackedPendingInput
windowState.trackedPendingInput = nil
}
}
}
}

@ViewBuilder
private var addForegroundWindowToContextButton: some View {
private var addWindowToContextButton: some View {
if accessibilityEnabled,
autoContextFromCurrentWindow,
!(windowBeingAddedToContext || windowAlreadyInContext),
let foregroundWindow = windowState?.foregroundWindow
let windowState = windowState,
let foregroundWindow = windowState.foregroundWindow
{
let foregroundWindowName = WindowHelpers.getWindowName(window: foregroundWindow.element)
let iconBundleURL = WindowHelpers.getWindowAppBundleUrl(window: foregroundWindow.element)

ContextTag(
ghostContextTag(
text: contextTagText,
textColor: .T_2,
hoverTextColor: .white,
background: contextTagBackground,
hoverBackground: contextTagHoverBackground,
hasHoverBorder: true,
shouldFadeIn: true,
iconBundleURL: iconBundleURL,
tooltip: "Add \(foregroundWindowName) Context"
) {
windowState?.addWindowToContext(window: foregroundWindow.element)
windowState.addWindowToContext(window: foregroundWindow.element)
}
}
}
Expand Down Expand Up @@ -211,6 +255,8 @@ extension FileRow {
iconView: Image(.text).addIconStyles(iconSize: 14)
) {
Defaults[.showHighlightedTextInput] = true
} removeAction: {
windowState?.pendingInput = nil
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions macos/Onit/UI/Settings/GeneralTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct GeneralTab: View {
@Default(.tetheredButtonHideAllApps) var tetheredButtonHideAllApps
@Default(.tetheredButtonHideAllAppsTimerDate) var tetheredButtonHideAllAppsTimerDate
@Default(.showHighlightedTextInput) var showHighlightedTextInput
@Default(.autoAddHighlightedTextToContext) var autoAddHighlightedTextToContext

@State var isLaunchAtStartupEnabled: Bool = SMAppService.mainApp.status == .enabled
@State var isAnalyticsEnabled: Bool = PostHogSDK.shared.isOptOut() == false
Expand Down Expand Up @@ -434,6 +435,19 @@ struct GeneralTab: View {
.controlSize(.small)
}
}

VStack(alignment: .leading, spacing: 20) {
HStack {
Text("Auto-add highlighted text to context.")
.font(.system(size: 13))

Spacer()

Toggle("", isOn: $autoAddHighlightedTextToContext)
.toggleStyle(.switch)
.controlSize(.small)
}
}
}
}

Expand Down