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

[Feature] Autofocus on text input area when activating window w/ hotkey #550

Closed
dsernst opened this issue Mar 4, 2023 · 3 comments
Closed
Labels
enhancement New feature or request

Comments

@dsernst
Copy link

dsernst commented Mar 4, 2023

Feature description

It would be a bit smoother and easier if the main ChatGPT text input box was autofocused as soon as the window is opened with the hotkey.

Motivation

Smoother and easier way to invoke chatgpt, more like the default Cmd+Space Spotlight search on Mac.

Alternatives

Thinking this could be possible with some custom javascript to find the element and focus on it. Something like:

function focusOnInput () {
  // This currently works because there is only a single `<textarea>` element on the ChatGPT UI page.
  document.getElementsByTagName("textarea")[0].focus()
}
  1. And then calling this function when the Open Window hotkey is pressed.

  2. Or Perhaps another option would be to hook into document.addEventListener("visibilitychange", focusOnInput), if the Page Visibility API works for this sort of application. Unclear if this would work when bringing the window into focus, but if it does, it would work for opening the window with a mouse or using the Application Switcher too (Cmd + Tab).

Additional context

No response

@dsernst dsernst added the enhancement New feature or request label Mar 4, 2023
@dsernst
Copy link
Author

dsernst commented Mar 4, 2023

Got this working! By adding to the main.js custom user script file:

document.addEventListener('visibilitychange', () =>
  document.getElementsByTagName('textarea')[0]?.focus()
)

@dsernst
Copy link
Author

dsernst commented Mar 4, 2023

Looking into where in the code this file is written, in order to make a PR so others can benefit from this as a new default.

Looks like this is where that file's default contents are being written?

"// *** ChatGPT User Script ***\n// @github: https://github.com/lencx/ChatGPT \n// @path: {}\n\nconsole.log('🤩 Hello ChatGPT!!!');",

@lencx
Copy link
Owner

lencx commented Mar 4, 2023

Thank you for the suggestion. This file is created during the application initialization and will not take effect for existing users since main.js already exists. I can consider adding it to the core script in the next version.

lencx added a commit that referenced this issue Mar 5, 2023
SsomsakTH pushed a commit to SsomsakTH/ChatGPT that referenced this issue Jul 24, 2023
@dsernst dsernst closed this as completed Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants