Text Highlight: Auto-add To Context#340
Conversation
* 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.
There was a problem hiding this comment.
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
- This PR is safe to merge as it adds user-controlled functionality while maintaining backward compatibility
- 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
- 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
| 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) | ||
| } |
There was a problem hiding this comment.
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!
timlenardo
left a comment
There was a problem hiding this comment.
This looks good, though we still need to switch the ordering of the Ghost Tags as discussed in our last meeting!
6226de8
into
feature/text-highlight/updated-input-view-behavior
* 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>
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
autoAddHighlightedTextToContextboolean property in the Defaults store (initialized totrue).autoAddHighlightedTextToContextistrue, the app defaults to the original text highlight behavior.autoAddHighlightedTextToContextisfalse, the highlighted text appears as the "ghost" button inFileRow, rather than automatically being added into context, and it takes precedence over the foreground window "ghost" button.trackedPendingInputstate inOnitPanelState.autoAddHighlightedTextToContextproperty can be toggled in the settings "General" tab, under the "Highlighted Text" section.pendingInputtonil.Parts
YOU ARE HERE