Skip to content

[Bug]: twitter post loses text content with paragraph breaks (\n\n) #93

@Astro-Han

Description

@Astro-Han

Description

opencli twitter post --text "..." loses text content when the input contains paragraph breaks (\n\n). Only the last line (typically a URL) is displayed in the posted tweet; all preceding paragraphs are lost.

Steps to Reproduce

# Works: single line
opencli twitter post --text "Hello world https://example.com"

# Works: line breaks without empty lines
opencli twitter post --text "Line 1\nLine 2\nhttps://example.com"

# Fails: paragraphs separated by empty lines
opencli twitter post --text "Paragraph 1\n\nParagraph 2\n\nhttps://example.com"
# Result: tweet only shows "https://example.com", paragraphs 1 and 2 are lost

Root Cause Analysis

post.ts:30 uses document.execCommand('insertText', ...) to type text into Twitter's Draft.js rich text editor. Draft.js represents paragraphs as <div> blocks internally, not \n characters. When insertText encounters \n\n, the editor state becomes corrupted and content is lost.

reply.ts uses the same insertion method and likely has the same issue (not yet confirmed).

Suggested Fix

Replace document.execCommand('insertText', ...) with ClipboardEvent (simulated paste). Draft.js has robust paste handling that properly parses multi-line text into paragraph blocks:

const dt = new DataTransfer();
dt.setData('text/plain', text);
box.dispatchEvent(new ClipboardEvent('paste', {
  bubbles: true, cancelable: true, clipboardData: dt
}));

This should be applied to both post.ts and reply.ts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions