Skip to content

Conversation

UNIDY2002
Copy link
Contributor

@UNIDY2002 UNIDY2002 commented Jul 24, 2025

I implemented superscript and subscript as AffineText attributes.

One missing thing is the toolbar icons, which is out of my reach.

Summary by CodeRabbit

  • New Features

    • Added support for superscript and subscript text formatting, including keyboard shortcuts and toolbar options.
    • Superscript and subscript styles are mutually exclusive and can be toggled on selected text.
    • Superscript and subscript text is now rendered using appropriate formatting in the editor.
  • Style

    • Updated editor rendering to visually display superscript and subscript text.

@UNIDY2002 UNIDY2002 requested a review from a team as a code owner July 24, 2025 08:57
Copy link
Contributor

coderabbitai bot commented Jul 24, 2025

Walkthrough

This change introduces support for superscript and subscript text formatting throughout the text editing system. It adds new attributes, rendering logic, commands, configuration options, and schema definitions to enable toggling, displaying, and storing superscript and subscript styles in text content.

Changes

File(s) Change Summary
.../affine/inlines/preset/src/command/config.ts Added superscript and subscript to textFormatConfigs with icons, hotkeys, and toggle actions.
.../affine/inlines/preset/src/command/text-style.ts Extended toggleTextStyleCommand to support superscript/subscript, ensuring mutual exclusivity.
.../affine/inlines/preset/src/default-inline-manager.ts Registered SuperscriptInlineSpecExtension and SubscriptInlineSpecExtension in specs array.
.../affine/inlines/preset/src/inline-spec.ts Added SuperscriptInlineSpecExtension and SubscriptInlineSpecExtension to InlineSpecExtensions.
.../affine/inlines/preset/src/nodes/affine-text.ts Updated AffineText rendering to wrap superscript/subscript text in / elements.
.../affine/shared/src/types/index.ts Added optional superscript and subscript boolean attributes to AffineTextStyleAttributes type.
.../framework/store/src/reactive/text/attributes.ts Added superscript and subscript to baseTextAttributes Zod schema.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Editor
    participant CommandSystem
    participant Renderer

    User->>Editor: Presses superscript/subscript hotkey
    Editor->>CommandSystem: toggleSuperscript / toggleSubscript
    CommandSystem->>Editor: Updates text attributes (mutually exclusive)
    Editor->>Renderer: Renders text
    Renderer-->>User: Displays <sup> or <sub> formatted text
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Suggested labels

app:core

Suggested reviewers

  • fengmk2

Poem

The rabbit hopped across the screen,
Superscript and subscript now can be seen!
With high and low in every line,
The text now sparkles, looking fine.
A hop, a skip, a code delight—
Formatting magic, day and night!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ff9a4f4 and 16f943a.

📒 Files selected for processing (7)
  • blocksuite/affine/inlines/preset/src/command/config.ts (2 hunks)
  • blocksuite/affine/inlines/preset/src/command/text-style.ts (4 hunks)
  • blocksuite/affine/inlines/preset/src/default-inline-manager.ts (2 hunks)
  • blocksuite/affine/inlines/preset/src/inline-spec.ts (2 hunks)
  • blocksuite/affine/inlines/preset/src/nodes/affine-text.ts (1 hunks)
  • blocksuite/affine/shared/src/types/index.ts (1 hunks)
  • blocksuite/framework/store/src/reactive/text/attributes.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
blocksuite/affine/inlines/preset/src/inline-spec.ts (1)
blocksuite/affine/shared/src/types/index.ts (1)
  • AffineTextAttributes (50-64)
blocksuite/affine/inlines/preset/src/default-inline-manager.ts (1)
blocksuite/affine/inlines/preset/src/inline-spec.ts (2)
  • SuperscriptInlineSpecExtension (110-122)
  • SubscriptInlineSpecExtension (124-136)
🔇 Additional comments (13)
blocksuite/affine/shared/src/types/index.ts (1)

46-47: LGTM! Type definitions follow established patterns.

The new superscript and subscript attributes are correctly defined with the same true | null pattern used by other text style attributes, ensuring consistency across the codebase.

blocksuite/framework/store/src/reactive/text/attributes.ts (1)

10-11: LGTM! Schema definitions are consistent and correct.

The new attributes follow the exact same Zod schema pattern as other boolean text attributes, ensuring proper validation and type safety.

blocksuite/affine/inlines/preset/src/default-inline-manager.ts (1)

17-18: LGTM! Inline spec extensions properly registered.

The new superscript and subscript extensions are correctly imported and added to the specs array, following the established pattern for other text formatting extensions.

Also applies to: 33-34

blocksuite/affine/inlines/preset/src/nodes/affine-text.ts (1)

23-32: LGTM! Rendering logic is correct and follows established patterns.

The implementation properly uses semantic HTML elements (<sup> and <sub>) and follows the same rendering pattern as other text attributes. The order of conditional checks ensures consistent behavior.

blocksuite/affine/inlines/preset/src/command/text-style.ts (3)

19-26: LGTM! Type extensions are consistent.

The new superscript and subscript keys are properly added to the allowed text style attributes, following the established pattern.

Also applies to: 73-80


34-42: LGTM! Mutual exclusivity logic is well-implemented.

The logic correctly ensures that superscript and subscript are mutually exclusive when activating:

  • When enabling superscript, subscript is cleared
  • When enabling subscript, superscript is cleared
  • Both can be deactivated independently

This provides intuitive behavior for users while maintaining data consistency.

Also applies to: 50-50


97-98: LGTM! Command exports follow established patterns.

The new toggle commands are properly exported using the same wrapper pattern as other text style commands.

blocksuite/affine/inlines/preset/src/inline-spec.ts (3)

110-122: LGTM! Superscript extension follows established patterns correctly.

The implementation is consistent with existing inline spec extensions. The schema validation, match function, and renderer are all appropriately implemented.


124-136: LGTM! Subscript extension follows established patterns correctly.

The implementation mirrors the superscript extension and is consistent with the existing codebase patterns.


146-147: LGTM! Extensions properly added to the exports array.

The new extensions are correctly included in the InlineSpecExtensions array, making them available for registration with the inline manager.

blocksuite/affine/inlines/preset/src/command/config.ts (3)

19-20: LGTM! Toggle commands properly imported.

The new toggle commands are correctly imported from the text-style module.


140-155: LGTM! Superscript configuration follows established patterns.

The configuration is properly structured with appropriate hotkey (Mod-+). Note that LinkIcon is used as a placeholder icon, which aligns with the PR description stating that toolbar icons were not included in this implementation.


156-171: LGTM! Subscript configuration follows established patterns.

The configuration is properly implemented with appropriate hotkey (Mod-=). Like the superscript config, it uses LinkIcon as a placeholder, which is expected based on the PR scope.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant