Skip to content

feat(swift): port @lexical/hashtag - #35

Merged
tmm merged 1 commit into
mainfrom
swift-hashtag
Nov 5, 2026
Merged

tmm merged 1 commit into
mainfrom
swift-hashtag

Conversation

@tmm

@tmm tmm commented Nov 5, 2026

Copy link
Copy Markdown
Member

Description

Ports @lexical/hashtag as LexicalHashtag: HashtagNode, createHashtagNode, isHashtagNode, HashtagExtension, HashtagConfig and registerLexicalHashtag, built on LexicalText's registerLexicalTextEntity. lexical-hashtag is enforced in the parity ledger.

JS matches hashtags with a regular expression that has the i flag and no u flag, so it reads UTF-16 code units and folds case with the spec's Canonicalize. Swift's regular expressions read Unicode scalars and fold case differently. So the same expression runs by hand over code units, with JS's character tables, including the CJK ranges that String.fromCharCode truncates. New vectors in vectors/entities check the matcher on 55 texts in many scripts. They also check the documents the transforms leave when text is set at once or typed one character at a time.

The TextKit views style a text node whose type is not text with the theme style of its type, as its createDOM adds that class, and the default theme gives hashtags the web playground's background. The playground's border-bottom is not drawn. The Swift playground registers HashtagExtension in both modes, as the web one does.

The hashtag cases that waited for this package are now ported: 34 in lexical-text and 6 in lexical-markdown (meta#5366). The ones that also need @lexical/mark stay skipped.

Test plan

Before

lexical-hashtag was not in the ledger, and lexical-text had 58 ported and 51 skipped.

After

  • swift format lint --strict --recursive Sources Tests Benchmarks Package.swift: clean
  • swift build --build-tests && swift test --skip-build: every suite passes; the known issues are the existing withKnownIssue cases, including upstream's test.fails for Bug: [lexical-text] A lookbehind matcher over repeated characters drops NodeState from a character the user did not type meta/lexical#9725
  • pnpm --filter lexical-conformance run test: Test Files 10 passed (10), Tests 24 passed (24)
  • pnpm --filter lexical-conformance run check-ledger: lexical-text | enforced | 109 | 92 | 17 | 0, lexical-hashtag | enforced | 1 | 1 | 0 | 0, lexical-markdown | enforced | 1064 | 616 | 448 | 0
  • npx tsc -p ./tsconfig.build.json --noEmit: clean
  • macOS playground (Xcode 27.2): a pasted "Try #hashtags and #swift, not word#tag. Also #日本語 and #über." shows the background on the four hashtags and not on word#tag. Typing could not be driven on the test Mac: synthetic keystrokes drop characters in every app there, TextEdit included.

Adds LexicalHashtag, ported from packages/lexical-hashtag/src: HashtagNode,
createHashtagNode, isHashtagNode, HashtagExtension, HashtagConfig and
registerLexicalHashtag, built on LexicalText's registerLexicalTextEntity.
lexical-hashtag is enforced in the parity ledger.

JS matches with a regular expression with the i flag and without u, which
reads UTF-16 code units and folds case with Canonicalize. The matcher runs
that expression by hand over code units with the same folding, from JS's
character tables. New vectors in vectors/entities check it on text in many
scripts, and the documents the transforms leave when text is set at once
or typed a character at a time.

The TextKit views style a text node of a type other than text with the
theme style of that type, as its createDOM adds that class, and the
default theme gives hashtags the web playground's background. The
playground registers HashtagExtension in both modes, as the web one does.

The hashtag cases that waited for this package are ported: 34 in
lexical-text and 6 in lexical-markdown (meta#5366). Those that also need
@lexical/mark stay skipped.

Amp-Thread-ID: https://ampcode.com/threads/T-01a19fce-8f8f-751a-afa3-961a37bb1a98
@tmm
tmm merged commit 616a8fe into main Nov 5, 2026
22 checks passed
@tmm
tmm deleted the swift-hashtag branch November 5, 2026 09:09
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