This commit is contained in:
roomote-v0[bot] 2026-04-23 13:59:35 +00:00 committed by GitHub
commit d832844373
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -245,7 +245,7 @@ export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
}, [selectedType, searchQuery])
const handleEnhancePrompt = useCallback(() => {
const trimmedInput = inputValue.trim()
const trimmedInput = (inputValue ?? "").trim()
if (trimmedInput) {
setIsEnhancingPrompt(true)
@ -259,7 +259,7 @@ export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
// Memoized check for whether the input has content (text or images)
const hasInputContent = useMemo(() => {
return inputValue.trim().length > 0 || selectedImages.length > 0
return (inputValue ?? "").trim().length > 0 || selectedImages.length > 0
}, [inputValue, selectedImages])
// Compute the key combination text for the send button tooltip based on enterBehavior
@ -509,8 +509,9 @@ export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
}
if (event.key === "Backspace" && !isComposing) {
const charBeforeCursor = inputValue[cursorPosition - 1]
const charAfterCursor = inputValue[cursorPosition + 1]
const safeInputValue = inputValue ?? ""
const charBeforeCursor = safeInputValue[cursorPosition - 1]
const charAfterCursor = safeInputValue[cursorPosition + 1]
const charBeforeIsWhitespace =
charBeforeCursor === " " || charBeforeCursor === "\n" || charBeforeCursor === "\r\n"
@ -522,7 +523,7 @@ export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
if (
charBeforeIsWhitespace &&
// "$" is added to ensure the match occurs at the end of the string.
inputValue.slice(0, cursorPosition - 1).match(new RegExp(mentionRegex.source + "$"))
safeInputValue.slice(0, cursorPosition - 1).match(new RegExp(mentionRegex.source + "$"))
) {
const newCursorPosition = cursorPosition - 1
// If mention is followed by another word, then instead
@ -537,9 +538,9 @@ export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
setCursorPosition(newCursorPosition)
setJustDeletedSpaceAfterMention(true)
} else if (justDeletedSpaceAfterMention) {
const { newText, newPosition } = removeMention(inputValue, cursorPosition)
if (newText !== inputValue) {
const { newText, newPosition } = removeMention(safeInputValue, cursorPosition)
if (newText !== safeInputValue) {
event.preventDefault()
setInputValue(newText)
setIntendedCursorPosition(newPosition) // Store the new cursor position in state
@ -677,8 +678,9 @@ export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
if (urlRegex.test(pastedText.trim())) {
e.preventDefault()
const trimmedUrl = pastedText.trim()
const safeInputValue = inputValue ?? ""
const newValue =
inputValue.slice(0, cursorPosition) + trimmedUrl + " " + inputValue.slice(cursorPosition)
safeInputValue.slice(0, cursorPosition) + trimmedUrl + " " + safeInputValue.slice(cursorPosition)
setInputValue(newValue)
const newCursorPosition = cursorPosition + trimmedUrl.length + 1
setCursorPosition(newCursorPosition)
@ -823,7 +825,8 @@ export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
if (lines.length > 0) {
// Process each line as a separate file path
let newValue = inputValue.slice(0, cursorPosition)
const safeInputValue = inputValue ?? ""
let newValue = safeInputValue.slice(0, cursorPosition)
let totalLength = 0
// Using a standard for loop instead of forEach for potential performance gains.
@ -842,7 +845,7 @@ export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
}
// Add space after the last mention and append the rest of the input
newValue += " " + inputValue.slice(cursorPosition)
newValue += " " + safeInputValue.slice(cursorPosition)
totalLength += 1
setInputValue(newValue)