Skip to content

Draft.js: caret/selection control before URL append (must land on new line after body) #128

Description

@Trace824

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:
    1. Type or insert body text.
    2. Without explicitly moving caret to end / new line, append https://… via insert_text or type_text.
    3. 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions