Skip to content

Commit 51b4c2b

Browse files
committed
PR feedback
1 parent e757fd9 commit 51b4c2b

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

webview-ui/src/components/chat/ChatTextArea.tsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,23 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
125125
// Select all text first
126126
textarea.select()
127127

128-
// Use execCommand to replace text while preserving undo history
129-
if (document.execCommand) {
130-
document.execCommand("insertText", false, message.text)
131-
} else {
132-
// Fallback for browsers that don't support execCommand
133-
// This approach also preserves undo history in modern browsers
134-
textarea.setRangeText(message.text, 0, textarea.value.length, "select")
135-
136-
// Trigger input event to notify React of the change
137-
const inputEvent = new Event("input", { bubbles: true })
138-
textarea.dispatchEvent(inputEvent)
128+
try {
129+
// Use execCommand to replace text while preserving undo history
130+
if (document.execCommand) {
131+
document.execCommand("insertText", false, message.text)
132+
} else {
133+
// Fallback for browsers that don't support execCommand
134+
// This approach also preserves undo history in modern browsers
135+
textarea.setRangeText(message.text, 0, textarea.value.length, "select")
136+
137+
// Trigger input event to notify React of the change
138+
const inputEvent = new Event("input", { bubbles: true })
139+
textarea.dispatchEvent(inputEvent)
140+
}
141+
} catch (error) {
142+
// Fallback to direct value assignment if native methods fail
143+
console.warn("Native text replacement failed, falling back to direct assignment:", error)
144+
setInputValue(message.text)
139145
}
140146
}
141147

0 commit comments

Comments
 (0)