feat: add support for sending messages with Ctrl+Enter
This commit modifies the `initInputContainer` function to add support for sending messages with Ctrl+Enter. If the user presses Ctrl+Enter, the message is sent without adding a new line. If the user presses Enter without Ctrl or Shift, a new line is added to the input field. The commit also removes unnecessary whitespace.
This commit is contained in:
parent
99e75d8f46
commit
0445ae7931
@ -5,12 +5,17 @@ function initInputContainer() {
|
|||||||
const sendButton = document.getElementById('send-button');
|
const sendButton = document.getElementById('send-button');
|
||||||
|
|
||||||
messageInput.addEventListener('keypress', function (e) {
|
messageInput.addEventListener('keypress', function (e) {
|
||||||
if (e.key === 'Enter' && !e.shiftKey) {
|
if (e.key === 'Enter') {
|
||||||
|
if (e.ctrlKey) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const message = messageInput.value.trim();
|
const message = messageInput.value.trim();
|
||||||
if (message !== '') {
|
if (message !== '') {
|
||||||
sendButton.click();
|
sendButton.click();
|
||||||
}
|
}
|
||||||
|
} else if (!e.shiftKey) {
|
||||||
|
e.preventDefault();
|
||||||
|
messageInput.setRangeText('\n', messageInput.selectionStart, messageInput.selectionEnd, 'end');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user