Skip to content

fix: strip trailing newlines from pasted text to prevent list breakage - #2050

Merged
Philipinho merged 1 commit into
docmost:mainfrom
olivierlambert:fix/paste-trailing-newline-in-lists
Mar 28, 2026
Merged

Philipinho merged 1 commit into
docmost:mainfrom
olivierlambert:fix/paste-trailing-newline-in-lists

Conversation

@olivierlambert

@olivierlambert olivierlambert commented Mar 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Strip trailing newlines from pasted text before markdown conversion to prevent broken list behavior
  • Terminal output often ends with \n, which the markdown parser (with breaks: true) converts to a <br>, creating an empty line outside the list item
  • This caused backspace on the empty line to incorrectly remove the previous bullet's formatting instead of joining lines

Fixes #2049

Test plan

  • Create a bullet point in the editor
  • Paste terminal output (e.g. uname -a) into the bullet
  • Verify no extra empty line is created after the pasted text
  • Verify pressing Enter after the pasted text creates a new bullet point
  • Verify pasting markdown content from VS Code still works correctly

🤖 Generated with Claude Code

Terminals (GNOME Terminal, etc.) include trailing whitespace in their
HTML clipboard data. ProseMirror parses this as an extra paragraph,
which inside a list item creates an orphan empty line that breaks the
list structure. Pressing backspace on that empty line then incorrectly
removes the bullet formatting of the previous line.

The fix adds a transformPasted handler that strips trailing
whitespace-only paragraphs from the pasted slice before insertion.
This runs on the final slice regardless of clipboard source (HTML or
plain text), so it catches all paste paths.

Fixes docmost#2049

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@olivierlambert
olivierlambert force-pushed the fix/paste-trailing-newline-in-lists branch from 0d9064c to ad9dd70 Compare March 25, 2026 13:36
@fallen

fallen commented Mar 25, 2026

Copy link
Copy Markdown

I was able to test this PR with my usual reproducer:

  • create a bullet point
  • paste the output of uname -a

Now with this PR, after pasting, it does not create the empty newline anymore and I don't have the bug.
I can then hit enter to continue adding new bullet point items.

👍

@olivierlambert

olivierlambert commented Mar 25, 2026 •

Copy link
Copy Markdown
Contributor Author

@Philipinho we split the PR code (done on my side) with the functional testing (done @fallen side), and we are happy so say that #2049 is fixed with this 👍

@Philipinho
Philipinho merged commit a42ac3d into docmost:main Mar 28, 2026
1 check passed
@Philipinho

Copy link
Copy Markdown
Member

Thanks for contributing.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bullet point list are broken after pasting text

3 participants