mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-06 08:18:39 +00:00
fix: preserve undo history when selecting @ mention autocompletion
- Use document.execCommand("insertText") instead of directly setting input value
- This preserves the browser undo/redo stack, allowing Ctrl+Z to undo autocompletion
- Follows the same pattern already used for enhanced prompt feature
- Fixes #8310
This commit is contained in:
parent
bf1aafad9b
commit
287ec589e5
1 changed files with 20 additions and 1 deletions
|
|
@ -371,7 +371,26 @@ export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
|
|||
isSlashCommand,
|
||||
)
|
||||
|
||||
setInputValue(newValue)
|
||||
// Use execCommand to preserve undo history
|
||||
try {
|
||||
if (document.execCommand) {
|
||||
// Focus the textarea to ensure it's the active element
|
||||
textAreaRef.current.focus()
|
||||
|
||||
// Select all text first
|
||||
textAreaRef.current.select()
|
||||
|
||||
// Insert the new text using execCommand to preserve undo stack
|
||||
document.execCommand("insertText", false, newValue)
|
||||
} else {
|
||||
// Fallback to direct value setting if execCommand is not available
|
||||
setInputValue(newValue)
|
||||
}
|
||||
} catch {
|
||||
// Fallback to direct value setting if execCommand fails
|
||||
setInputValue(newValue)
|
||||
}
|
||||
|
||||
const newCursorPosition = newValue.indexOf(" ", mentionIndex + insertValue.length) + 1
|
||||
setCursorPosition(newCursorPosition)
|
||||
setIntendedCursorPosition(newCursorPosition)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue