Skip to content

Comments

Text Highlight: Auto-add To Context#340

Merged
lk340 merged 2 commits intofeature/text-highlight/updated-input-view-behaviorfrom
feature/text-highlight/auto-add-to-context
Jul 18, 2025
Merged

Text Highlight: Auto-add To Context#340
lk340 merged 2 commits intofeature/text-highlight/updated-input-view-behaviorfrom
feature/text-highlight/auto-add-to-context

Conversation

@lk340
Copy link
Collaborator

@lk340 lk340 commented Jul 16, 2025

This is part 2 in a series of mini-PRs that tackle various aspects of the overarching text highlight context experience.
Please review this after reviewing the first PR.

Summary

  • This PR tackles the auto-adding nature of text highlights, namely togging the auto-adding of highlighted text into context on/off.
  • Auto-adding behavior is set by the autoAddHighlightedTextToContext boolean property in the Defaults store (initialized to true).
  • When autoAddHighlightedTextToContext is true, the app defaults to the original text highlight behavior.
  • When autoAddHighlightedTextToContext is false, the highlighted text appears as the "ghost" button in FileRow, rather than automatically being added into context, and it takes precedence over the foreground window "ghost" button.
    • The "ghost" button tracks the highlighted text through the new trackedPendingInput state in OnitPanelState.
    • Clicking on the text highlight "ghost" button adds the highlighted text into context.
  • The autoAddHighlightedTextToContext property can be toggled in the settings "General" tab, under the "Highlighted Text" section.
  • Add a remove action to the highlighted text context tag, which sets pendingInput to nil.

Parts

  1. Text Highlight: Update Highlighted Text Behavior #339
  2. YOU ARE HERE
  3. Text Highlight (Pin - 1): Update to Data Files and OnitPanelState #342 (Pin 1)
  4. Text Highlight (Pin - 2): Update to Managers and UI #343 (Pin 2)
  5. Text Highlight: Pin #341 (Pin 3)

* Add new `autoAddHighlightedTextToContext` boolean property to Defaults store. Property defaults to `true`.
* Add new switch button to settings "General" tab to toggle `autoAddHighlightedTextToContext` boolean.
* Add new `trackedPendingInput` property to OnitPanelState to track highlighted text when `autoAddHighlightedTextToContext` is `false`.
* When `autoAddHighlightedTextToContext` is `false`, highlighting text reveals the "ghost" context tag in FileRow to manually add highlighted text to context.
* When `autoAddHighlightedTextToContext` is `true`, the app maintains previous highlight behavior (auto-adding to context). If some text was already highlighted, this switch will automatically add the highlighted text to context.
* Update highlighted text ContextTag to have a remove action for highlighted text context.
@lk340 lk340 requested a review from timlenardo July 16, 2025 19:59
@lk340 lk340 self-assigned this Jul 16, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Summary

This PR introduces a configurable setting for controlling how highlighted text is added to context. Previously, highlighted text was always automatically added to context, but now users can toggle this behavior off, causing highlighted text to appear as a "ghost" button that requires manual confirmation.

The implementation adds a new autoAddHighlightedTextToContext default setting (defaulting to true) and introduces a trackedPendingInput state to handle text that is highlighted but not automatically added. The changes are well-integrated across the accessibility manager, panel state, settings UI, and file row components.

The code maintains backward compatibility by defaulting to the original auto-add behavior while providing an opt-out mechanism through settings. This change is part of a larger effort to improve text highlight handling, focusing specifically on giving users more control over when highlighted text becomes part of the context.

Confidence score: 4/5

  1. This PR is safe to merge as it adds user-controlled functionality while maintaining backward compatibility
  2. Score of 4 given because while the changes are well-structured and isolated, the interaction between accessibility features and UI state management warrants careful testing
  3. Files needing attention:
    • AccessibilityNotificationsManager.swift - Verify the null handling in processSelectedText
    • FileRow.swift - Check the onChange handler for potential edge cases

5 files reviewed, no comments
Edit PR Review Bot Settings | Greptile

Comment on lines 178 to 210
private var addToContextButton: some View {
if accessibilityEnabled {
if 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
}
}
} else if autoContextFromCurrentWindow,
!(windowBeingAddedToContext || windowAlreadyInContext),
let foregroundWindow = windowState?.foregroundWindow
{
let foregroundWindowName = WindowHelpers.getWindowName(window: foregroundWindow.element)
let iconBundleURL = WindowHelpers.getWindowAppBundleUrl(window: foregroundWindow.element)

ghostContextTag(
text: contextTagText,
iconBundleURL: iconBundleURL,
tooltip: "Add \(foregroundWindowName) Context"
) {
windowState?.addWindowToContext(window: foregroundWindow.element)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s check with Elise when she’s online, but I would prefer to keep these as two separate ghost tags. While some designs have used a shared tag, I don’t think that’s the best user experience. Elise has mentioned that she often highlights text randomly, so hiding the main window ghost tag every time there is highlighted text seems like it will be irritating. Since the simplicity of adding the main window is a big value of our product, I think we should always keep that front and center!

Copy link
Contributor

@timlenardo timlenardo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, though we still need to switch the ordering of the Ghost Tags as discussed in our last meeting!

@lk340 lk340 merged commit 6226de8 into feature/text-highlight/updated-input-view-behavior Jul 18, 2025
1 check passed
lk340 added a commit that referenced this pull request Jul 18, 2025
* Update highlighted text behavior.

* Add `showHighlightedTextInput` Defaults property. This handles the permanent showing/hiding of the `inputView`.
* `inputView` can now be permanently hidden.
* Update settings "General" tab to allow for toggling of `showHighlightedTextInput` boolean, which determines the show/hide behavior of `inputView`.
* FileRow now shows highlighted text as a ContextTag. Clicking on the ContextTag toggles `showHighlightedTextInput` to `true`, revealing the `inputView` if it were hidden.

* Remove period from highlight text settings

* Address feedback

* Fix whitespace and new lines being included in highlighted text.
* Remove copy and close buttons in InputTitle. Caret button no longer toggles height of `inputView`; it now handles removing the `inputView` from the UI (previous close button behavior).
* Because the caret button no longer toggles the height of `inputView`, height toggle logic has been removed.

* Text Highlight: Auto-add To Context (#340)

* Add toggle feature to auto-adding of highlighted text to context.
* Add new `autoAddHighlightedTextToContext` boolean property to Defaults store. Property defaults to `true`.
* Add new switch button to settings "General" tab to toggle `autoAddHighlightedTextToContext` boolean.
* Add new `trackedPendingInput` property to OnitPanelState to track highlighted text when `autoAddHighlightedTextToContext` is `false`.
* When `autoAddHighlightedTextToContext` is `false`, highlighting text reveals the "ghost" context tag in FileRow to manually add highlighted text to context.
* When `autoAddHighlightedTextToContext` is `true`, the app maintains previous highlight behavior (auto-adding to context). If some text was already highlighted, this switch will automatically add the highlighted text to context.
* Update highlighted text ContextTag to have a remove action for highlighted text context.
* Update to show both ghost tags in FileRow.

* Address Feedback & Fixes

* Remove trimming on the `processSelectedText()` level and apply it only on the context tags level instead.
* Add new StringHelpers struct for reusable removable of whitespace + new lines.
* Update ordering of context tags in FileRow.
* Update hiding of InputView to the PromptCore level. InputView can now be seen in the FinalContextView, regardless of show state.
* Update InputView to be a collapsible element when in FinalContextView.

* Apply new UI update to text highlight experience

* Increase max height of InputView.
* `highlightedTextContext` button now shows border when InputView is active. Update ContextTag to make this type of update more reusable.
* Update `inputString` output in InputTitle.
* Update background, borders and spacing around InputView.
* InputView is now inside of PromptCore to reflect design updates.
* Update spacing in PromptCore.

* small update to arrow rotation in finalcontextview

---------

Co-authored-by: timl <tim.lenardo@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants