Skip to content

refactor(editor): narrow text format parameter #12946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: canary
Choose a base branch
from

Conversation

L-Sun
Copy link
Member

@L-Sun L-Sun commented Jun 27, 2025

PR Dependency Tree

This tree was auto-generated by Charcoal

Summary by CodeRabbit

  • Refactor

    • Updated terminology and types from "text style" to "text attributes" throughout the text formatting features for improved clarity and consistency.
    • Separated style-specific attributes (like bold, italic, color, and background) from other text metadata.
    • Renamed relevant commands and updated menu and toolbar configurations to use the new attribute structure.
  • New Features

    • Added support for color and background properties in text style attributes.
  • Bug Fixes

    • Improved consistency and reliability in text formatting and highlighting behavior.

Copy link
Contributor

coderabbitai bot commented Jun 27, 2025

Walkthrough

The changes restructure text attribute types by introducing AffineTextStyleAttributes for style-specific properties and refactoring AffineTextAttributes as an intersection type. Command and utility function names are updated for clarity, and all relevant type annotations and usages are revised to align with the new structure. No control flow or logic is altered.

Changes

File(s) Change Summary
.../shared/src/types/index.ts Split AffineTextAttributes into AffineTextStyleAttributes (includes color, background) and redefined AffineTextAttributes.
.../inlines/preset/src/command/text-style.ts
.../utils.ts
.../index.ts
Renamed functions/commands from "Style" to "Attributes", updated types and returned property names for consistency.
.../inlines/preset/src/command/format-text.ts Updated formatTextCommand to use AffineTextStyleAttributes for the styles parameter.
.../inlines/preset/src/command/config.ts Replaced all isTextStyleActive references with isTextAttributeActive.
.../blocks/root/src/configs/toolbar.ts Changed updateHighlight parameter type from AffineTextAttributes to HighlightType.
.../components/src/highlight-dropdown-menu/dropdown-menu.ts Updated highlight handling to use new HighlightType, refactored event handlers and types.
.../widgets/keyboard-toolbar/src/config.ts Replaced getTextStyle with getTextAttributes, updated types and variable names accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant UI
    participant Toolbar
    participant Command
    participant Types

    UI->>Toolbar: User triggers text style/highlight change
    Toolbar->>Command: Call command with AffineTextStyleAttributes
    Command->>Types: Use AffineTextStyleAttributes for style, AffineTextAttributes for full attributes
    Command-->>Toolbar: Return updated attributes
    Toolbar-->>UI: Update UI with new styles/attributes
Loading

Suggested labels

app:core

Poem

In the warren, attributes split in two,
Style and meaning—now clear what they do!
Commands renamed, types refined,
Rabbits hop with logic aligned.
Colors and highlights, all in their place—
Code now runs with elegant grace!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
blocksuite/affine/inlines/preset/src/command/utils.ts (1)

80-81: Address the static analysis hint about void in union type.

The static analysis tool correctly identifies that void in union types can be confusing. Consider using undefined instead for better clarity.

  ) => { textAttributes: AffineTextAttributes } | boolean | void
+ ) => { textAttributes: AffineTextAttributes } | boolean | undefined
blocksuite/affine/inlines/preset/src/command/text-style.ts (1)

75-78: Address the static analysis hint about empty object type.

The static analysis tool correctly identifies that {} is too permissive. Consider using a more specific type or Record<string, never> for an empty object.

-export const getTextAttributes: Command<
-  {},
-  { textAttributes: AffineTextAttributes }
-> = (ctx, next) => {
+export const getTextAttributes: Command<
+  Record<string, never>,
+  { textAttributes: AffineTextAttributes }
+> = (ctx, next) => {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a7185e4 and c9778ff.

📒 Files selected for processing (9)
  • blocksuite/affine/blocks/root/src/configs/toolbar.ts (2 hunks)
  • blocksuite/affine/components/src/highlight-dropdown-menu/dropdown-menu.ts (5 hunks)
  • blocksuite/affine/inlines/preset/src/command/config.ts (7 hunks)
  • blocksuite/affine/inlines/preset/src/command/format-text.ts (2 hunks)
  • blocksuite/affine/inlines/preset/src/command/index.ts (1 hunks)
  • blocksuite/affine/inlines/preset/src/command/text-style.ts (3 hunks)
  • blocksuite/affine/inlines/preset/src/command/utils.ts (2 hunks)
  • blocksuite/affine/shared/src/types/index.ts (1 hunks)
  • blocksuite/affine/widgets/keyboard-toolbar/src/config.ts (11 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (8)
blocksuite/affine/inlines/preset/src/command/config.ts (1)
blocksuite/affine/inlines/preset/src/command/text-style.ts (1)
  • isTextAttributeActive (89-110)
blocksuite/affine/inlines/preset/src/command/format-text.ts (1)
blocksuite/affine/shared/src/types/index.ts (1)
  • AffineTextStyleAttributes (38-46)
blocksuite/affine/blocks/root/src/configs/toolbar.ts (1)
blocksuite/affine/components/src/highlight-dropdown-menu/dropdown-menu.ts (1)
  • HighlightType (23-26)
blocksuite/affine/widgets/keyboard-toolbar/src/config.ts (3)
blocksuite/affine/inlines/preset/src/command/text-style.ts (1)
  • getTextAttributes (75-87)
blocksuite/affine/widgets/keyboard-toolbar/src/icons.ts (1)
  • HighLightDuotoneIcon (31-49)
blocksuite/affine/shared/src/types/index.ts (1)
  • AffineTextStyleAttributes (38-46)
blocksuite/affine/shared/src/types/index.ts (1)
blocksuite/affine/model/src/consts/doc.ts (2)
  • ReferenceInfo (58-58)
  • FootNote (93-93)
blocksuite/affine/components/src/highlight-dropdown-menu/dropdown-menu.ts (1)
blocksuite/affine/shared/src/types/index.ts (1)
  • AffineTextStyleAttributes (38-46)
blocksuite/affine/inlines/preset/src/command/utils.ts (2)
blocksuite/affine/shared/src/types/index.ts (1)
  • AffineTextAttributes (48-61)
blocksuite/affine/shared/src/services/toolbar-service/context.ts (1)
  • chain (33-35)
blocksuite/affine/inlines/preset/src/command/text-style.ts (3)
blocksuite/affine/inlines/preset/src/command/index.ts (3)
  • toggleTextStyleCommand (19-19)
  • isTextAttributeActive (14-14)
  • getTextAttributes (13-13)
blocksuite/affine/shared/src/types/index.ts (2)
  • AffineTextStyleAttributes (38-46)
  • AffineTextAttributes (48-61)
blocksuite/affine/inlines/preset/src/command/utils.ts (1)
  • getCombinedTextAttributes (177-202)
🪛 Biome (1.9.4)
blocksuite/affine/inlines/preset/src/command/utils.ts

[error] 80-80: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

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

[error] 76-76: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

⏰ Context from checks skipped due to timeout of 90000ms (53)
  • GitHub Check: Unit Test (5)
  • GitHub Check: Unit Test (4)
  • GitHub Check: Unit Test (2)
  • GitHub Check: Unit Test (3)
  • GitHub Check: Unit Test (1)
  • GitHub Check: Native Unit Test
  • GitHub Check: E2E BlockSuite Cross Browser Test (2, webkit)
  • GitHub Check: E2E Test (8)
  • GitHub Check: E2E Test (2)
  • GitHub Check: E2E Test (5)
  • GitHub Check: E2E Test (10)
  • GitHub Check: E2E Test (7)
  • GitHub Check: E2E Test (9)
  • GitHub Check: E2E BlockSuite Cross Browser Test (1, firefox)
  • GitHub Check: E2E Test (6)
  • GitHub Check: E2E Test (4)
  • GitHub Check: E2E Test (3)
  • GitHub Check: E2E BlockSuite Cross Browser Test (2, chromium)
  • GitHub Check: E2E Test (1)
  • GitHub Check: Build Server native
  • GitHub Check: E2E BlockSuite Cross Browser Test (2, firefox)
  • GitHub Check: E2E BlockSuite Test (2)
  • GitHub Check: E2E BlockSuite Test (10)
  • GitHub Check: E2E BlockSuite Cross Browser Test (1, webkit)
  • GitHub Check: E2E BlockSuite Test (1)
  • GitHub Check: E2E BlockSuite Cross Browser Test (1, chromium)
  • GitHub Check: E2E BlockSuite Test (7)
  • GitHub Check: E2E BlockSuite Test (6)
  • GitHub Check: E2E BlockSuite Test (9)
  • GitHub Check: Run native tests
  • GitHub Check: E2E BlockSuite Test (3)
  • GitHub Check: E2E BlockSuite Test (8)
  • GitHub Check: E2E BlockSuite Test (5)
  • GitHub Check: E2E BlockSuite Test (4)
  • GitHub Check: E2E Mobile Test (4)
  • GitHub Check: E2E Mobile Test (3)
  • GitHub Check: E2E Mobile Test (5)
  • GitHub Check: fuzzing
  • GitHub Check: E2E Mobile Test (2)
  • GitHub Check: y-octo binding test on x86_64-pc-windows-msvc
  • GitHub Check: y-octo binding test on x86_64-apple-darwin
  • GitHub Check: Build AFFiNE native (aarch64-pc-windows-msvc)
  • GitHub Check: E2E Mobile Test (1)
  • GitHub Check: Build AFFiNE native (x86_64-pc-windows-msvc)
  • GitHub Check: y-octo binding test on aarch64-pc-windows-msvc
  • GitHub Check: loom thread test
  • GitHub Check: Analyze (typescript, blocksuite)
  • GitHub Check: Analyze (typescript, affine)
  • GitHub Check: Build @affine/electron renderer
  • GitHub Check: Analyze (javascript, blocksuite)
  • GitHub Check: Analyze (javascript, affine)
  • GitHub Check: Typecheck
  • GitHub Check: Lint
🔇 Additional comments (18)
blocksuite/affine/shared/src/types/index.ts (1)

38-61: Excellent type refactoring for better separation of concerns.

The introduction of AffineTextStyleAttributes for style-specific properties and the refactoring of AffineTextAttributes as an intersection type is a clean architectural improvement. This separation allows components to work with only the attributes they need (e.g., formatting commands with style attributes only) while maintaining backward compatibility.

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

14-14: LGTM: Consistent import update.

The import correctly reflects the renamed command from isTextStyleActive to isTextAttributeActive.


41-121: LGTM: All usages consistently updated.

All text format configurations properly use the renamed isTextAttributeActive command. The updates are consistent across all format types (bold, italic, underline, strike, code, link).

blocksuite/affine/inlines/preset/src/command/format-text.ts (2)

3-6: LGTM: Added necessary import for type narrowing.

The import of AffineTextStyleAttributes is correctly added to support the parameter type change.


19-19: Excellent type narrowing for better semantic correctness.

Changing the styles parameter type from AffineTextAttributes to AffineTextStyleAttributes is semantically correct. The format text command should only accept style attributes (bold, italic, color, background, etc.) and not metadata attributes (links, references, footnotes, etc.). This improves type safety and prevents misuse.

blocksuite/affine/blocks/root/src/configs/toolbar.ts (2)

12-12: LGTM: Import updated for more precise typing.

The import change to use HighlightType aligns with the type narrowing for the highlight functionality.


143-143: Perfect type narrowing for highlight functionality.

Changing the parameter type from AffineTextAttributes to HighlightType is semantically correct. The highlight function should only accept color and background properties, and HighlightType (defined as Pick<AffineTextStyleAttributes, 'color' | 'background'>) provides exactly that precision.

blocksuite/affine/inlines/preset/src/command/index.ts (1)

13-14: LGTM: Consistent export renaming.

The exports are correctly renamed from getTextStylegetTextAttributes and isTextStyleActiveisTextAttributeActive, maintaining consistency with the broader refactor to use "text attributes" terminology.

blocksuite/affine/widgets/keyboard-toolbar/src/config.ts (3)

29-29: LGTM: Consistent import updates align with the refactor.

The import changes from getTextStyle to getTextAttributes and from AffineTextAttributes to AffineTextStyleAttributes are well-coordinated and improve type specificity for style-related operations.

Also applies to: 48-48


820-821: LGTM: Variable renaming is consistent across all text style operations.

The consistent renaming from textStyle to textAttributes maintains clarity and aligns with the broader refactoring effort throughout the codebase.

Also applies to: 831-832, 842-843, 853-854, 864-865, 875-876, 886-888


919-919: LGTM: Type narrowing improves type safety.

Using AffineTextStyleAttributes instead of AffineTextAttributes for style payloads is a good improvement that provides more specific typing for style-only operations.

Also applies to: 964-964

blocksuite/affine/inlines/preset/src/command/utils.ts (1)

177-202: LGTM: Function renaming is consistent with the refactor.

The renaming from getCombinedTextStyle to getCombinedTextAttributes and the property updates from textStyle to textAttributes align well with the broader refactoring effort.

blocksuite/affine/components/src/highlight-dropdown-menu/dropdown-menu.ts (3)

1-1: Excellent type refinement improves API design.

The import change to AffineTextStyleAttributes and the redefinition of HighlightType as a Pick type provides better type safety and clearly communicates which properties are relevant for highlighting operations.

Also applies to: 23-26


39-39: LGTM: Simplified API design with single parameter.

The refactor from separate value and type parameters to a single style object parameter simplifies the API and makes it more maintainable.

Also applies to: 41-45


77-77: LGTM: Event handlers updated to use object syntax.

The event handlers now correctly pass style objects with { color: value } and { background: value } syntax, which aligns with the new API design.

Also applies to: 98-98

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

5-8: LGTM: Import updates support the type refactoring.

The addition of both AffineTextAttributes and AffineTextStyleAttributes imports and the function rename from getCombinedTextStyle to getCombinedTextAttributes are consistent with the broader refactor.

Also applies to: 14-14


16-21: LGTM: Type narrowing for style-specific operations.

Using AffineTextStyleAttributes for style toggle operations is a good improvement that provides more specific typing and better type safety.

Also applies to: 53-57


75-87: LGTM: Command renaming and implementation updates are consistent.

The renaming from getTextStyle to getTextAttributes and isTextStyleActive to isTextAttributeActive, along with the updated property access patterns, maintains consistency across the refactor.

Also applies to: 89-110

Copy link

codecov bot commented Jun 27, 2025

Codecov Report

Attention: Patch coverage is 10.34483% with 26 lines in your changes missing coverage. Please review.

Project coverage is 56.23%. Comparing base (12fce1f) to head (c9778ff).
Report is 43 commits behind head on canary.

Files with missing lines Patch % Lines
...uite/affine/widgets/keyboard-toolbar/src/config.ts 0.00% 15 Missing ⚠️
...te/affine/inlines/preset/src/command/text-style.ts 25.00% 6 Missing ⚠️
...nents/src/highlight-dropdown-menu/dropdown-menu.ts 20.00% 4 Missing ⚠️
...ocksuite/affine/blocks/root/src/configs/toolbar.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           canary   #12946      +/-   ##
==========================================
+ Coverage   55.93%   56.23%   +0.29%     
==========================================
  Files        2659     2669      +10     
  Lines      127378   127727     +349     
  Branches    20068    20127      +59     
==========================================
+ Hits        71252    71822     +570     
+ Misses      53791    53736      -55     
+ Partials     2335     2169     -166     
Flag Coverage Δ
server-test 79.01% <ø> (+0.08%) ⬆️
unittest 31.89% <10.34%> (+0.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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