-
Notifications
You must be signed in to change notification settings - Fork 38
Text Highlight: Pin #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature/text-highlight/updated-input-view-behavior
Are you sure you want to change the base?
Text Highlight: Pin #341
Conversation
There was a problem hiding this 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 updates the FileRow component to support pinned text highlighting functionality. The key changes include:
- Splitting highlighted text items into separate unpinned and pinned sections
- Adding state management for transitions between pinned/unpinned states
- Implementing morphing behavior between ghost tags and context tags
- Adding proper cleanup for UI elements when removing highlighted text items
This is part 3 of a larger feature implementation, focusing specifically on the FileRow component updates. The changes maintain backward compatibility while adding new pinning capabilities.
Confidence score: 4/5
- This PR appears safe to merge as it's a well-isolated component update with clear state management
- The high score is due to the focused scope and clear separation of concerns in the implementation
- Key files to review:
macos/Onit/UI/Prompt/Files/FileRow.swift- Verify the state transitions between pinned/unpinned items
1 file reviewed, no comments
Edit PR Review Bot Settings | Greptile
… with pinned text highlight updates. * `AccessibliityNotificationsManager` now properly handles removing `InputView` from the UI when it matches the current highlighted text, and the current highlighted text is about to be removed. * `AccessibliityNotificationsManager` also now handles setting the unpinned highlighted context and showing it in the UI. * `KeyboardShortcutsManager` now clears all states related to highlighted text.
* Add pin icon. * ContextTag can now handle the pin action and shows pinned corner icon when pinned. * ExternalTetheredButton now accounts for both auto-highlighted and tracked highlighted text. * InputView `smallRemove` button now clears the unpinned highlighted text context tag when it matches the removed InputView text. * Update FinalContextView to now show full array of input (highlighted text) contexts. * Update PromptCore to properly show the selected highlighted text context.
abd8a3a to
916f84b
Compare
timlenardo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @lk340 - thanks for getting this up! Unfortunately, I am unable to run it due to a crash that occurs when I try to instantiate the data container, now that the SwiftData has changed.
Fixing this is going to be a big task, and it feels like a niche product. How many people will really want to pin lots of highlighted text? It doesn't seem like a major user behavior, so I think we should set this aside for now and revisit it after we've addressed some more pressing matters.
Regardless, I left some comments so you can understand the issues.
| let pendingInputs = inputs[index] | ||
|
|
||
| if let input = inputs[index], !input.selectedText.isEmpty { | ||
| message += "\n\nUse the following selected text as context. When present, selected text should take priority over other context." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also update this to respect the ordering of the selected text. For example, if there's 4 highlighted text sections pinned and they send a prompt like "rephrase this", I think they're probably referring to the most recently added highlight.
So this prompt should be modified to say like "the selected text should be given priority in the order they appear", and then we need to make sure that the most recent highlighted text is added first (which probably isn't the default, since we most likely use 'append').
| } else if state.pendingInput != nil { | ||
| state.pendingInput = nil | ||
| } else if state.hasHighlightedText { | ||
| state.clearHighlightedTextStates() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I wonder if this should only clear out the most recent, instead of all of them. It seems like it might be irritating if you hit Escape by accident and it clears your entire context window.
Without really playing with it, my intuition is that we should:
- Only do this if the user is in the mode where highlights get auto-added.
- Only do it for the automatically added highlight, not any that they've pinned.
| private let borderColor: Color? | ||
| private let iconBundleURL: URL? | ||
| private let iconView: (any View)? | ||
| private let iconViewCornerIcon: ImageResource? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd probably call this the 'leftIcon' and 'rightIcon' instead of 'iconView' and 'iconViewCornerIcon'. That's what this new field is, right? It's a new right-aligned icon?
| tooltip: String? = nil, | ||
| errorDotColor: Color? = nil, | ||
| action: (() -> Void)? = nil, | ||
| pinAction: (() -> Void)? = nil, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling this 'pinAction' makes it specific to pinning, which defeats the purpose of a general name like 'iconViewCornerIcon'. If we're only supporting a pin action, there's no need to pass in the CornerIcon; it can just be hardcoded. Alternatively, if we want to make this general, we should give both new fields corresponding generic names, like "rightIcon" and "rightIconAction." Either approach works for me since we have no immediate plans for anything other than pinning, but it should be one or the other.
| var instruction: String | ||
| var timestamp: Date | ||
| var input: Input? | ||
| var inputs: [Input] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were you able to get this code to run on your computer? It's insta-crashing for me. We can't change anything in any of the SwiftData model objects (Prompt, Chat, SystemPrompt, etc - search for the @model decorator) without writing a migration. In this case, transitioning from an optional Input to a non-optional input array results in a fatal error. Many of my old chats have a value of 'nil' for the 'input', which can't be converted into a non-optional array.
To reproduce the issue, checkout an older version of the app and send a prompt with no Input. Then, check out this branch and run it. You'll get a fatal error.
You can see some examples of migrations I've written in the past ('maybeUpdatePromptPriorInstructions' and 'maybeCleanupHangingPromptReferences') in SwiftDataContainer. It's a pain in the ass, but you have to do it if you want to change anything in Swift Data.
| if let cornerIcon = iconViewCornerIcon { | ||
| ZStack(alignment: .center) { | ||
| Circle() | ||
| .fill(isHoveredBody ? hoverBackground : background) | ||
| .frame(width: 13, height: 13) | ||
|
|
||
| Image(cornerIcon) | ||
| .addIconStyles(iconSize: 7.45) | ||
| } | ||
| .offset(x: 4, y: 4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From reading the code, I can't tell the difference between this icon and the hoverActionButton added below. Do we need both?
Summary
This PR tackles the "pinned" portion of the new text highlight experience.
Parts (Pin 1 and Pin 2 have been closed)
YOU ARE HERE(Pin 3)