fix(twitter): fix newline handling in post command via clipboard paste (#107)

Co-authored-by: zhutiancillm <zhutiancillm@users.noreply.github.com>
This commit is contained in:
zhutiancillmandzhutiancillm authored and GitHub committed 2026-03-20 10:20:13 +08:00
1 parent 055403abc1
commit ebc5c09ad9
1 file changed
+9 -2
+9 -2
View File
@@ -26,8 +26,15 @@ cli({
const box = document.querySelector('[data-testid="tweetTextarea_0"]');
if (box) {
box.focus();
// insertText is the most reliable way to trigger React's onChange events
document.execCommand('insertText', false, ${JSON.stringify(kwargs.text)});
// Simulate a paste event to properly handle newlines in Draft.js/React
const textToInsert = ${JSON.stringify(kwargs.text)};
const dataTransfer = new DataTransfer();
dataTransfer.setData('text/plain', textToInsert);
box.dispatchEvent(new ClipboardEvent('paste', {
clipboardData: dataTransfer,
bubbles: true,
cancelable: true
}));
} else {
return { ok: false, message: 'Could not find the tweet composer text area.' };
}