Skip to content

[lexical-markdown] Bug Fix: hashtag no longer blocks the heading shortcut - #8978

Closed
LeSingh1 wants to merge 1 commit into
meta:mainfrom
LeSingh1:fix/5366-hashtag-blocks-heading-shortcut
Closed

LeSingh1 wants to merge 1 commit into
meta:mainfrom
LeSingh1:fix/5366-hashtag-blocks-heading-shortcut

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Typing ## in front of existing text leaves the literal ## in a paragraph instead of producing an h2.

registerMarkdownShortcuts only runs its transformers when the update looks like a single typed character, which it checks by comparing the anchor offset against the previous anchor offset. A node transform can split or merge the leaves around the caret inside that same update, which moves the anchor into a different node and makes the two raw offsets incomparable.

##Welcome is exactly that: the hashtag entity claims #Welcome, so the caret ends up at offset 1 of the hashtag node. Typing the space breaks the hashtag and merges everything back into one text node at offset 3, which reads as a two-character jump, and the heading transformer never runs. # works; ## through ###### do not. That matches the reporter's own analysis in the thread.

Rebase both offsets on the parent element before comparing them. When the leaves around the caret are unchanged this adds the same constant to both sides, so the existing comparison is unaffected — it only changes the case where a node transform moved the caret into a different leaf.

Adds a headless unit test covering # through ###### with the hashtag entity registered, and a playground e2e for the reported repro. The # case passes either way and is a control.

Fixes #5366

…tcut

`registerMarkdownShortcuts` only runs its transformers when the update looks
like a single typed character, which it checks by comparing the anchor offset
against the previous anchor offset. A node transform can split or merge the
leaves around the caret in the same update, which moves the anchor into a
different node and makes the two raw offsets incomparable.

Typing `##` in front of existing text is exactly that case: the hashtag entity
matches `#Welcome` inside `##Welcome`, so the caret ends up at offset 1 of the
hashtag node. Typing the space then breaks the hashtag and merges everything
back into one text node at offset 3, which reads as a jump of two characters,
and the heading transformer never runs.

Rebase both offsets on the parent element before comparing them. When the
leaves around the caret are unchanged this adds the same constant on both
sides, so the existing comparison is unaffected.
@vercel

vercel Bot commented Aug 8, 2026

Copy link
Copy Markdown

@LeSingh1 is attempting to deploy a commit to the Meta Open Source Team on Vercel.

A member of the Team first needs to authorize it.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 8, 2026
@LeSingh1

Copy link
Copy Markdown
Contributor Author

Consolidated into #9055 with the other PRs that share this defect, per @etrepum's note on #9027 and @mayrang's on #9035. Same fix and same tests, one review.

@LeSingh1 LeSingh1 closed this Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Hashtag blocks transformation to Headings

1 participant