fix: prevent backspace from deleting files when text contains whitespace (#10261)

- Change condition from text.trim() === '' to text.length === 0
- Users can now delete whitespace characters (spaces, tabs, newlines) without accidentally deleting attached files
- File deletion only occurs when text is completely empty
- Maintains existing functionality for file deletion when text is truly empty

Fixes: Blank character input causes backspace to incorrectly delete attached images

Signed-off-by: zhaokun <zhaokun_zhang@icloud.com>
This commit is contained in:
Zhaokun 2025-09-19 18:26:13 +08:00 committed by GitHub
parent 63be1d8cf2
commit 1e615d69e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -377,7 +377,7 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic, topic }) =
}
}
if (event.key === 'Backspace' && text.trim() === '' && files.length > 0) {
if (event.key === 'Backspace' && text.length === 0 && files.length > 0) {
setFiles((prev) => prev.slice(0, -1))
return event.preventDefault()
}