Skip to content

Commit

Permalink
feat: autofocus (#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
lencx committed Mar 5, 2023
1 parent ce395e0 commit e3e0c86
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src-tauri/src/scripts/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ async function init() {
childList: true,
subtree: true,
});
document.addEventListener('visibilitychange', () =>
document.getElementsByTagName('textarea')[0]?.focus()
);
}

function chatBtns() {
Expand Down Expand Up @@ -92,6 +95,11 @@ function copyToClipboard(text, btn) {
}, 1000);
}

function focusOnInput() {
// This currently works because there is only a single `<textarea>` element on the ChatGPT UI page.
document.getElementsByTagName("textarea")[0].focus();
}

function setIcon(type) {
return {
copy: `<svg class="chatappico copy" stroke="currentColor" fill="none" stroke-width="2" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" class="h-4 w-4" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"></path><rect x="8" y="2" width="8" height="4" rx="1" ry="1"></rect></svg>`,
Expand Down

0 comments on commit e3e0c86

Please sign in to comment.