mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-26 21:28:50 +01:00
🛠️ fix: Correct Unwanted Newlines after Undo in Textarea (#2289)
* docs: edit docker_override note for deploy-compose
* 🛠️ fix: Correct Unwanted Newlines after Undo in Textarea
This commit is contained in:
parent
f146db5c59
commit
7bd03a6e70
3 changed files with 39 additions and 9 deletions
|
|
@ -32,9 +32,28 @@ export function insertTextAtCursor(element: HTMLTextAreaElement, textToInsert: s
|
|||
3) Reseting back to scrollHeight reads and applies the ideal height for the current content dynamically
|
||||
*/
|
||||
export const forceResize = (textAreaRef: React.RefObject<HTMLTextAreaElement>) => {
|
||||
if (textAreaRef.current) {
|
||||
textAreaRef.current.style.height = 'auto';
|
||||
textAreaRef.current.offsetHeight;
|
||||
textAreaRef.current.style.height = `${textAreaRef.current.scrollHeight}px`;
|
||||
if (!textAreaRef.current) {
|
||||
return;
|
||||
}
|
||||
textAreaRef.current.style.height = 'auto';
|
||||
textAreaRef.current.offsetHeight;
|
||||
textAreaRef.current.style.height = `${textAreaRef.current.scrollHeight}px`;
|
||||
};
|
||||
|
||||
/**
|
||||
* Necessary undo event helper for edge cases where undoing pasted content leaves newlines filling the previous container height.
|
||||
*/
|
||||
export const trimUndoneRange = (textAreaRef: React.RefObject<HTMLTextAreaElement>) => {
|
||||
if (!textAreaRef.current) {
|
||||
return;
|
||||
}
|
||||
const { value, selectionStart, selectionEnd } = textAreaRef.current;
|
||||
const afterCursor = value.substring(selectionEnd).trim();
|
||||
if (afterCursor.length) {
|
||||
return;
|
||||
}
|
||||
const beforeCursor = value.substring(0, selectionStart);
|
||||
const newValue = beforeCursor + afterCursor;
|
||||
textAreaRef.current.value = newValue;
|
||||
textAreaRef.current.setSelectionRange(selectionStart, selectionStart);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue