Skip to content

Commit

Permalink
try to make the chat input resize correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Concedo authored and Concedo committed Dec 3, 2023
1 parent d1f2468 commit 3b32eee
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10502,9 +10502,24 @@
{
//resize chat inp
let textarea = document.getElementById("cht_inp");
let numberOfLineBreaks = (textarea.value.match(/\n/g) || []).length;
numberOfLineBreaks = numberOfLineBreaks>4?4:numberOfLineBreaks;
textarea.rows = numberOfLineBreaks+1;

let textlines = textarea.value.split("\n");
let numberOfLineBreaks = textlines.length;
let lengthtester = document.getElementById("cht_inp_lengthtester");
for(let l=0;l<textlines.length;++l)
{
lengthtester.innerText = textlines[l];
if(textarea.offsetWidth>0)
{
numberOfLineBreaks += Math.floor(lengthtester.offsetWidth / textarea.offsetWidth );
}
}
lengthtester.innerText = "";
numberOfLineBreaks = numberOfLineBreaks>5?5:numberOfLineBreaks;
textarea.rows = numberOfLineBreaks;

// textarea.style.height = "auto";
// textarea.style.height = textarea.scrollHeight + 3 + "px";
}
function chat_submit_generation()
{
Expand Down Expand Up @@ -11526,7 +11541,8 @@
<div class="cht_inp_hold">
<button onclick="show_groupchat_select()" id="chat_btnmode_chat" class="chat_btnmode_chat hidden" type="button"></button>
<div id="cht_inp_bg" class="cht_inp_bg">
<textarea class="cht_inp_bg_inner" id="cht_inp" type="text" name="chtchtinp" role="presentation" autocomplete="noppynop" spellcheck="true" rows="1" wrap="off" placeholder="Type a message" value="" oninput="update_submit_button();chat_resize_input();" onkeypress="return chat_handle_typing(event)"/></textarea>
<div class="cht_inp_bg_inner" id="cht_inp_lengthtester" style="white-space: nowrap; visibility: hidden; height: 0px; position:absolute; width: auto;"></div>
<textarea class="cht_inp_bg_inner" id="cht_inp" type="text" name="chtchtinp" role="presentation" autocomplete="noppynop" spellcheck="true" rows="1" wrap="on" placeholder="Type a message" value="" oninput="update_submit_button();chat_resize_input();" onkeypress="return chat_handle_typing(event)"/></textarea>
</div>
<button onclick="chat_submit_generation()" id="chat_msg_send_btn" class="chat_msg_send_btn" type="button"></button>
<button onclick="abort_generation()" id="chat_msg_send_btn_abort" class="hidden chat_msg_send_btn_abort" type="button"></button>
Expand Down

0 comments on commit 3b32eee

Please sign in to comment.