Skip to content

Comments

feat: add behavior names and trace logging#2218

Draft
christianhg wants to merge 2 commits intomainfrom
feat/behavior-names
Draft

feat: add behavior names and trace logging#2218
christianhg wants to merge 2 commits intomainfrom
feat/behavior-names

Conversation

@christianhg
Copy link
Member

@christianhg christianhg commented Feb 19, 2026

Two commits:

1. Add name field to Behavior type and name all behaviors

Add optional name?: string to the Behavior type. Name all behaviors across core, abstract, plugin, toolbar, and playground files:

  • Core behaviors use their existing variable names (clearListOnEnter, breakingAtTheEndOfTextBlock)
  • Abstract behaviors use names derived from their purpose (deleteBackwardMergeBlocks, firefoxEnterCollapse)
  • Toolbar behaviors use template literals with the schema type name so the trace shows the specific decorator/style/annotation (toolbar:decoratorShortcut:code, toolbar:mutuallyExclusiveAnnotation:link)
  • Plugin behaviors use static names with a namespace prefix (pasteLinkOnSelection, typeahead:escape, typeahead:submitMatch)
  • Playground behaviors use a namespace prefix (codeEditor:moveBlockUp)

2. Add trace logging to performEvent

Add debugEnabled.behaviors flag to debug.ts to guard string formatting in the hot path. Add structured trace output to the behavior evaluation loop:

pte:behaviors > insert.break (send:native) -- 4 candidates
pte:behaviors   [1/4] clearListOnEnter -- guard: false
pte:behaviors   [2/4] breakingAtTheEndOfTextBlock -- guard: passed -> 1 action set(s)
pte:behaviors   (skipped 2 remaining)

Nested raise/forward/execute calls indent automatically:

pte:behaviors > keyboard.keydown (send:native) -- 2 candidates
pte:behaviors   [1/2] firefoxEnterCollapse -- guard: passed -> 1 action set(s)
pte:behaviors   > insert.break (raise:synthetic) -- 4 candidates
pte:behaviors     [1/4] clearListOnEnter -- guard: false
pte:behaviors     [2/4] breakingAtTheEndOfTextBlock -- guard: passed -> 1 action set(s)

Enable with localStorage.debug = 'pte:behaviors' in browser or DEBUG=pte:behaviors in Node.

@vercel
Copy link

vercel bot commented Feb 19, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
portable-text-editor-documentation Ready Ready Preview, Comment Feb 19, 2026 0:00am
portable-text-example-basic Ready Ready Preview, Comment Feb 19, 2026 0:00am
portable-text-playground Ready Ready Preview, Comment Feb 19, 2026 0:00am

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Feb 19, 2026

🦋 Changeset detected

Latest commit: c9481a8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
@portabletext/editor Minor
@portabletext/plugin-character-pair-decorator Major
@portabletext/plugin-emoji-picker Patch
@portabletext/plugin-input-rule Patch
@portabletext/plugin-markdown-shortcuts Major
@portabletext/plugin-one-line Major
@portabletext/plugin-paste-link Major
@portabletext/plugin-sdk-value Major
@portabletext/plugin-typeahead-picker Patch
@portabletext/plugin-typography Patch
@portabletext/toolbar Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Add optional name?: string to the Behavior type for debug tracing.
Name all 116 behaviors across core, abstract, and plugin files.
Core behaviors use their existing variable names (e.g.,
clearListOnEnter). Abstract behaviors use names derived from
their purpose (e.g., deleteBackwardMergeBlocks).
Add debugEnabled.behaviors flag to guard string formatting.
Log entry (event type, mode, candidate count), per-behavior
guard results, and skipped remainder count. Indent nested
raise/forward/execute calls.

Enable with localStorage.debug = 'pte:behaviors' in browser
or DEBUG=pte:behaviors in Node.
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.

1 participant