Skip to content

Preserve whitespace around custom attachment.#1102

Open
arthurwozniak wants to merge 2 commits into
basecamp:mainfrom
arthurwozniak:fix/preserve-space-around-formatted-attachment
Open

Preserve whitespace around custom attachment.#1102
arthurwozniak wants to merge 2 commits into
basecamp:mainfrom
arthurwozniak:fix/preserve-space-around-formatted-attachment

Conversation

@arthurwozniak

Copy link
Copy Markdown

Summary

Importing HTML into the editor dropped the space between formatted text and an inline custom attachment (mention, placeholder): <strong>Link: </strong><action-text-attachment> came back as Link: glued to the attachment. The space survived in the saved value but vanished on re-edit.

Lexical strips the ASCII whitespace bordering an inline decorator on import, and CustomActionTextAttachmentNode re-adds it from the neighbouring sibling. That restore only ran for bare text nodes, so when the bordering text was wrapped in an inline format (<strong>, <mark>, etc) the sibling was an element and the space was lost.

Changes

src/nodes/custom_action_text_attachment_node.js - read the sibling's textContent instead of requiring a bare text node, so the space counts inside inline formats. Match ASCII whitespace ([ \t\r\n]) rather than \s, which also matches NBSP - whitespace Lexical keeps - and would inject a phantom space.

Copilot AI review requested due to automatic review settings June 10, 2026 07:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds regression coverage and adjusts HTML import conversion to correctly preserve whitespace adjacent to custom action text attachments, including handling NBSP without introducing extra “phantom” spaces.

Changes:

  • Added browser tests to validate whitespace preservation around custom attachments (including NBSP cases).
  • Updated DOM conversion logic to detect ASCII whitespace adjacent to attachments without matching NBSP.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
test/browser/tests/attachments/custom_attachment_whitespace.test.js Adds Playwright coverage for whitespace behavior around custom attachments.
src/nodes/custom_action_text_attachment_node.js Tweaks whitespace detection regex to avoid treating NBSP as whitespace while preserving adjacent ASCII whitespace.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +30 to 36
// Preserve the space Lexical strips next to the attachment. ASCII only:
// \s also matches NBSP, which Lexical keeps, so it would add a phantom space.
const nodes = []
const previousSibling = attachment.previousSibling
if (previousSibling && previousSibling.nodeType === Node.TEXT_NODE && /\s$/.test(previousSibling.textContent)) {
if (previousSibling && /[ \t\r\n]$/.test(previousSibling.textContent)) {
nodes.push($createTextNode(" "))
}
Comment on lines +48 to 50
if (nextSibling && /^[ \t\r\n]/.test(nextSibling.textContent)) {
nodes.push($createTextNode(" "))
}
const nodes = []
const previousSibling = attachment.previousSibling
if (previousSibling && previousSibling.nodeType === Node.TEXT_NODE && /\s$/.test(previousSibling.textContent)) {
if (previousSibling && /[ \t\r\n]$/.test(previousSibling.textContent)) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR preserves original codestyle.


const nextSibling = attachment.nextSibling
if (nextSibling && nextSibling.nodeType === Node.TEXT_NODE && /^\s/.test(nextSibling.textContent)) {
if (nextSibling && /^[ \t\r\n]/.test(nextSibling.textContent)) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR preserves original codestyle.

Comment on lines +34 to 36
if (previousSibling && /[ \t\r\n]$/.test(previousSibling.textContent)) {
nodes.push($createTextNode(" "))
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in a6810d2

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.

2 participants