Skip to content

Commit

Permalink
Merge pull request #17 from mebis-lp/MBS-9399-copy-questions
Browse files Browse the repository at this point in the history
MBS-9399: Add copy button to questions
  • Loading branch information
PhMemmel authored Jan 16, 2025
2 parents e582468 + 0005c4e commit 5b84254
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion amd/build/dialog.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion amd/build/dialog.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion amd/build/helper.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/build/helper.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions amd/src/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,8 @@ const showMessage = async(text, sender = '', answer = true) => {
const {html, js} = await Templates.renderForPromise('block_ai_chat/message', templateData);
Templates.appendNodeContents('.block_ai_chat-output', html, js);

// Add copy listener for replys.
if (sender === '') {
helper.attachCopyListenerLast();
}
// Add copy listener for question and reply.
helper.attachCopyListenerLast();

// Scroll the modal content to the bottom.
helper.scrollToBottom();
Expand Down
10 changes: 7 additions & 3 deletions amd/src/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ export const copyToClipboard = (element) => {
*/
export const attachCopyListenerLast = () => {
const elements = document.querySelectorAll(".block_ai_chat_modal .copy");
const last = elements[elements.length - 1];
last.addEventListener('click', function() {
copyToClipboard(last);
const lastquestion = elements[elements.length - 2];
lastquestion.addEventListener('click', function() {
copyToClipboard(lastquestion);
});
const lastanswer = elements[elements.length - 1];
lastanswer.addEventListener('click', function() {
copyToClipboard(lastanswer);
});
};

Expand Down
2 changes: 1 addition & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
right: 0;
padding: 0.5rem 0.75rem 2.5rem 2.75rem;
}
.block_ai_chat_modal .message.ai:hover .copy {
.block_ai_chat_modal .message:hover .copy {
visibility: visible;
cursor: pointer;
}
Expand Down
4 changes: 2 additions & 2 deletions styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
right: 0;
padding: .5rem .75rem 2.5rem 2.75rem;
}
.message.ai:hover .copy {
.message:hover .copy {
visibility: visible;
cursor: pointer;
}
Expand Down Expand Up @@ -361,4 +361,4 @@ body.block_ai_chat_replacehelp {
#ai_chat_button {
bottom: 1.9rem;
}
}
}

0 comments on commit 5b84254

Please sign in to comment.