Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/clis/twitter/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ 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)});
// Use ClipboardEvent paste: Draft.js handles paste robustly,
// while execCommand('insertText') corrupts state on multi-paragraph text (\n\n)
const dt = new DataTransfer();
dt.setData('text/plain', ${JSON.stringify(kwargs.text)});
box.dispatchEvent(new ClipboardEvent('paste', {
bubbles: true, cancelable: true, clipboardData: dt
}));
} else {
return { ok: false, message: 'Could not find the tweet composer text area.' };
}
Expand Down
8 changes: 7 additions & 1 deletion src/clis/twitter/reply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ cli({
const box = document.querySelector('[data-testid="tweetTextarea_0"]');
if (box) {
box.focus();
document.execCommand('insertText', false, ${JSON.stringify(kwargs.text)});
// Use ClipboardEvent paste: Draft.js handles paste robustly,
// while execCommand('insertText') corrupts state on multi-paragraph text (\n\n)
const dt = new DataTransfer();
dt.setData('text/plain', ${JSON.stringify(kwargs.text)});
box.dispatchEvent(new ClipboardEvent('paste', {
bubbles: true, cancelable: true, clipboardData: dt
}));
} else {
return { ok: false, message: 'Could not find the reply text area. Are you logged in?' };
}
Expand Down
Loading