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:
1 parent
055403abc1
commit
ebc5c09ad9
1 file changed
+9
-2
@@ -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.' };
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user