-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: pasting into edit message breaks ctrl+z #3959
Comments
I have a fix, but going down the rabbit hole of clipboard api I wrote code that should work only on browsers in the IE 11 to the next few years. I could not find the browser support target of the project... If needed, we can easily add support for IE 7+ (by just trying multiple old apis). export function handlePasteAsPlainText(
event: ExtendedClipboardEvent,
textAreaRef: React.RefObject<HTMLTextAreaElement>,
setEditedText: React.Dispatch<React.SetStateAction<string>>,
) {
event.preventDefault();
console.log('Paste as plain text event triggered');
let text = '';
// Get pasted text from various possible sources
if (event.clipboardData || event.originalEvent?.clipboardData) {
text = (event.originalEvent?.clipboardData || event.clipboardData).getData('text/plain');
console.log('Plain text obtained from clipboardData');
} else if (window.clipboardData !== undefined) {
text = window.clipboardData.getData('Text');
console.log('Plain text obtained from window.clipboardData');
} else {
console.log('Unable to obtain pasted plain text from clipboard');
}
console.log('Pasted plain text:', text);
const textArea = textAreaRef.current;
if (!textArea) {
console.log('TextArea ref is null');
return;
}
// Check if document.queryCommandSupported exists
const supportsQueryCommand = typeof document.queryCommandSupported === 'function';
// Try to use execCommand for better undo/redo support
if (supportsQueryCommand && document.queryCommandSupported('insertText')) {
console.log('Using insertText command for plain text');
document.execCommand('insertText', false, text);
console.log('Plain text inserted using insertText command');
} else if (supportsQueryCommand && document.queryCommandSupported('paste')) {
console.log('Using paste command for plain text');
document.execCommand('paste', false, text);
console.log('Plain text inserted using paste command');
} else {
console.log('ExecCommand not supported, using fallback method for plain text');
// Fall back to the original implementation if execCommand is not supported
const start = textArea.selectionStart;
const end = textArea.selectionEnd;
const newValue = textArea.value.substring(0, start) + text + textArea.value.substring(end);
setEditedText(newValue);
console.log('Plain text inserted using fallback method');
}
console.log('Final textarea value after plain text paste:', textArea.value);
} |
This issue was solved for the main chat input textarea, the same fix will need to be applied. I will try to address it tonight, since there is another issue there I need to address. |
the specific fix for this was in the following commit: 46c47e7 |
What happened?
When editing a past message after pasting test I'm unable to ctrl+z.
This is because of #1942
Steps to Reproduce
What browsers are you seeing the problem on?
No response
Relevant log output
No response
Screenshots
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: