fix(context): detect clipboard fallback copy by content, not by change#285
Merged
Conversation
Signed-off-by: Logan Nguyen <lg.131.dev@gmail.com>
Signed-off-by: Logan Nguyen <lg.131.dev@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Selected-text context capture silently failed when re-selecting and re-querying the same passage in a row: the host-app picker bar showed no quoted context, and nothing was attached to the message.
What changed
clipboard_fallback()incontext.rs(used whenever the macOS Accessibility API can't expose a selection directly, e.g. web-based rich-text editors) detected a successful synthetic Cmd+C by diffing clipboard contents before vs. after. If the clipboard already held the exact same text as the new selection, the diff came back unchanged, so the function concluded nothing had been copied and returned no context — even though the copy succeeded.Fix: clear the pasteboard before issuing the synthetic Cmd+C, then check for non-empty content afterward instead of "did it change." This detects a real copy even when it's byte-identical to what was already there, while still restoring the original clipboard contents afterward.
Testing
changed=falsedespite a real selection) and confirmed the fix resolves it across repeated captures of the same text.bun run test:all:coverage— 100% line coverage, all green.bun run validate-build— zero warnings/errors.