fix copilot insertion so it doesn't wipe existing query text #1803
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.
Preview this branch
This is a fix for an issue I noticed (and that we've had some customer feedback on) with Copilot query insertion. The current version of the copilot insertion logic will replace the active query in some circumstances. It's notable that after the first result replaces the query, we do properly add the query to the end in further copilot invocations:
Note: It's worth noting that with Undo fixed, you can undo that replacement, which you'll see me doing at the end of the video
recording-before-fix.mp4
With this fix, the query is now always inserted at the end of the document. It's possible we could insert it at the cursor position but that's a fair bit more work. This seems a little less surprising to me than replacing the entire query:
recording-after-fix.mp4
In looking into this, I noticed that we only append the copilot response to the end if and only if there is a previous generated query. That logic didn't seem correct to me. It seems like we should always insert the copilot response at the end. However, I don't have the history or context to understand why that choice was made originally, or if it was just an error. So if I'm misunderstanding something here, I'm happy to look in to other approaches! This fix seems to do the trick though, and ensure that we're always appending copilot responses to the end.