Summary
When appending a URL after the compose body, the caret/selection is often not at the end of the Draft.js editor. The URL inserts mid-sentence, producing mangled published text (URL spliced into the body).
Repro
- Context: x.com Draft.js compose with multi-line intent: opinion body, then site URL on its own line.
- Steps:
- Type or insert body text.
- Without explicitly moving caret to end / new line, append
https://… via insert_text or type_text.
- Inspect draft (and published status if sent).
- Observed: URL lands mid-sentence, e.g. body text interrupted by
https://full-selfbrowsing.com/ then remaining words.
- Example of mangled public post pattern: URL embedded inside the sentence rather than on its own trailing line.
Code pointers (verified against /workspace/FSB)
extension/content/actions.js — placeCaretAtEnd (~L3492); draft_fast_path append branch collapses range to end (~L2979–2985); resolveEditableTarget (~L2107) for nested contenteditable under tweetTextarea_0.
extension/background.js — cdpInsertText does not guarantee Draft selection-at-end before Input.insertText (~L20055+).
extension/site-guides/social/twitter.js — compose selectors (tweetTextarea_0, tweet buttons).
Proposed fix
Before any append insert into Draft.js compose: resolve the editable root, place caret at end (Range collapse false), optionally insert a leading \n when the last char is not newline, then insert. CDP path should focus + set selection via the same helper or a small shared content/CDP preamble so caret cannot remain mid-body.
Acceptance / regression
- Append URL always appears after full body, on its own line when requested.
- No mid-sentence splice across repeated appends.
- Fixture test for caret-at-end before insert.
Owner
extension
Priority: P0 · Owner: extension
Summary
When appending a URL after the compose body, the caret/selection is often not at the end of the Draft.js editor. The URL inserts mid-sentence, producing mangled published text (URL spliced into the body).
Repro
https://…viainsert_textortype_text.https://full-selfbrowsing.com/then remaining words.Code pointers (verified against /workspace/FSB)
extension/content/actions.js—placeCaretAtEnd(~L3492); draft_fast_path append branch collapses range to end (~L2979–2985);resolveEditableTarget(~L2107) for nested contenteditable undertweetTextarea_0.extension/background.js—cdpInsertTextdoes not guarantee Draft selection-at-end beforeInput.insertText(~L20055+).extension/site-guides/social/twitter.js— compose selectors (tweetTextarea_0, tweet buttons).Proposed fix
Before any append insert into Draft.js compose: resolve the editable root, place caret at end (Range collapse false), optionally insert a leading
\nwhen the last char is not newline, then insert. CDP path should focus + set selection via the same helper or a small shared content/CDP preamble so caret cannot remain mid-body.Acceptance / regression
Owner
extension
Priority: P0 · Owner: extension