Skip to content
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

Chat: Fix input focus issue #3147

Merged
merged 8 commits into from
Feb 14, 2024
Merged

Chat: Fix input focus issue #3147

merged 8 commits into from
Feb 14, 2024

Conversation

abeatrix
Copy link
Contributor

CONTEXT: https://sourcegraph.slack.com/archives/C05AGQYD528/p1707784216516929

Fix an issue with editor focus being stolen by webview when webview is not focused.

This change updates the Chat.tsx component to pass the isWebviewActive prop to the inputCaretPosition and isFocusd props, which are used for setting the focus to the chat input box, respectively.
This PR updated to not set chat input focus when isWebviewActive is not true, meaning the editor is currently focused.

Test plan

All bots are green.

  1. put your cursor to an open file after sending a question to Cody
  2. once Cody has responded, make sure the cursor in the editor is still active
Screen.Recording.2024-02-12.at.4.50.39.PM.mov

Copy link
Contributor

@toolmantim toolmantim left a comment

Choose a reason for hiding this comment

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

Ah, this could be a good quick fix (though from an interaction POV I'd prefer it if we only changed keyboard focus if "Edit Message" had focus, which means the user didn't move and continue doing other things… even within the same webview).

This fix does seem to have this bug now though:

CleanShot.2024-02-13.at.12.46.51.mp4

@abeatrix
Copy link
Contributor Author

Ah, this could be a good quick fix (though from an interaction POV I'd prefer it if we only changed keyboard focus if "Edit Message" had focus, which means the user didn't move and continue doing other things… even within the same webview).

This fix does seem to have this bug now though:

CleanShot.2024-02-13.at.12.46.51.mp4

ah i forgot to remove the uEffect dependence. I think the latest commit should work now, but will test it more thoroughly tomorrow to confirm

@toolmantim
Copy link
Contributor

I gave this a quick test, but doesn't seem to work:

CleanShot.2024-02-14.at.10.55.13.mp4

@abeatrix
Copy link
Contributor Author

That helps! See the latest update:

Screen.Recording.2024-02-13.at.4.15.51.PM.mov

Do you know if we can use e2e test for this?

Copy link
Contributor

@toolmantim toolmantim left a comment

Choose a reason for hiding this comment

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

This seems to work great now!

There's still one improvement that I would have loved us do, which is to only_refocus the message input if "Edit Last Message" has focus. If the user is doing other things in the webview we shouldn't interrupt them (like it does below):

CleanShot.2024-02-14.at.13.05.50.mp4

@toolmantim
Copy link
Contributor

Do you know if we can use e2e test for this?

Not really sure! Is there a way to pause or slow down the LLM response in the e2e test perhaps? 🤔 @dominiccooney has done a lot of e2e work, and may have ideas? (e.g. how to test doing an edit, moving the focus during the stream, and then verifying an expectation… all before the stream completes)

@dominiccooney
Copy link
Contributor

Is there a way to pause or slow down the LLM response in the e2e test perhaps?

Yes, that sounds useful. You'll need to hack on vscode/test/fixtures/mock-server.ts and change the app.post('/.api/completions/code', (req, res) => { ... bit.

One cheesy but effective technique is to put "instructions" to the server in the request. For example you could send it some JavaScript in some marker tags in the chat, and then await new Function(str)(... pass whatever you need ...) (essentially, eval but with arguments) in the server. Or you could make a DSL or whatever.

Second idea is to actually have the mock server turn around and use/hand out Promises so you can precisely stage when things happen. You can look at how the mock graphql server is set up and used for some ideas.

Or you could do some combination of these two.

@abeatrix abeatrix merged commit 5062210 into main Feb 14, 2024
16 checks passed
@abeatrix abeatrix deleted the bee/fix-focus branch February 14, 2024 16:41
@abeatrix
Copy link
Contributor Author

There's still one improvement that I would have loved us do, which is to only_refocus the message input if "Edit Last Message" has focus.

Makes sense! Do you mind filing an issue so i can look into that after i'm done with my current issue?

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.

None yet

3 participants