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

feat: alert user that chat has been copied via aria-live #614

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/js/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -1962,6 +1962,7 @@ class ChatLLM {
*/
CopyChatHistory(e) {
let text = '';
let notificationText = '';
if (typeof e == 'undefined') {
// check for passthrough
// get html of the full chat history
Expand All @@ -1971,9 +1972,11 @@ class ChatLLM {
if (e.target.id == 'chatLLM_copy_all') {
// get html of the full chat history
text = document.getElementById('chatLLM_chat_history').innerHTML;
notificationText = 'Copied All.';
} else if (e.target.classList.contains('chatLLM_message_copy_button')) {
// get the text of the element before the button
text = e.target.closest('p').previousElementSibling.innerHTML;
notificationText = 'Copied.';
}
} else if (e.type == 'keyup') {
// check for alt shift c or ctrl shift c
Expand All @@ -1985,6 +1988,7 @@ class ChatLLM {
);
if (elem) {
text = elem.innerHTML;
notificationText = 'Copied.';
}
} else if (
e.key == 'A' &&
Expand All @@ -1994,6 +1998,7 @@ class ChatLLM {
e.preventDefault();
// get html of the full chat history
text = document.getElementById('chatLLM_chat_history').innerHTML;
notificationText = 'Copied All.';
}
}

Expand All @@ -2011,6 +2016,12 @@ class ChatLLM {
// this messes up a bit with spacing, so kill more than 2 newlines in a row
markdown = markdown.replace(/\n{3,}/g, '\n\n');

if (notificationText != '') {
if (display) {
display.announceText(notificationText);
}
}

try {
navigator.clipboard.writeText(markdown); // note: this fails if you're on the inspector. That's fine as it'll never happen to real users
} catch (err) {
Expand Down
Loading