Autofit immediately if input value is empty

This commit is contained in:
Cohee 2024-03-27 22:18:20 +02:00
parent 78400b4a2e
commit 55d855b655
1 changed files with 8 additions and 6 deletions

View File

@ -661,16 +661,18 @@ export async function initMovingUI() {
/**@type {HTMLTextAreaElement} */ /**@type {HTMLTextAreaElement} */
const sendTextArea = document.querySelector('#send_textarea'); const sendTextArea = document.querySelector('#send_textarea');
const chatBlock = document.getElementById('chat');
const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
/** /**
* this makes the chat input text area resize vertically to match the text size (limited by CSS at 50% window height) * this makes the chat input text area resize vertically to match the text size (limited by CSS at 50% window height)
*/ */
function autoFitSendTextArea() { function autoFitSendTextArea() {
const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
/**@type {HTMLDivElement} */
const chatBlock = document.querySelector('#chat');
const originalScrollBottom = chatBlock.scrollHeight - (chatBlock.scrollTop + chatBlock.offsetHeight); const originalScrollBottom = chatBlock.scrollHeight - (chatBlock.scrollTop + chatBlock.offsetHeight);
if (sendTextArea.scrollHeight == sendTextArea.offsetHeight) { if (sendTextArea.scrollHeight == sendTextArea.offsetHeight) {
sendTextArea.style.height = window.getComputedStyle(sendTextArea).getPropertyValue('min-height'); // Needs to be pulled dynamically because it is affected by font size changes
const sendTextAreaMinHeight = window.getComputedStyle(sendTextArea).getPropertyValue('min-height');
sendTextArea.style.height = sendTextAreaMinHeight;
} }
sendTextArea.style.height = sendTextArea.scrollHeight + 0.3 + 'px'; sendTextArea.style.height = sendTextArea.scrollHeight + 0.3 + 'px';
@ -843,8 +845,8 @@ export function initRossMods() {
saveSettingsDebounced(); saveSettingsDebounced();
}); });
$(sendTextArea).on('input', ()=>{ $(sendTextArea).on('input', () => {
if (sendTextArea.scrollHeight > sendTextArea.offsetHeight) { if (sendTextArea.scrollHeight > sendTextArea.offsetHeight || sendTextArea.value === '') {
autoFitSendTextArea(); autoFitSendTextArea();
} else { } else {
autoFitSendTextAreaDebounced(); autoFitSendTextAreaDebounced();