Skip to content
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

fix: word paste missing formats #67

Merged
merged 6 commits into from
Sep 19, 2024
Merged

Conversation

zzxming
Copy link
Collaborator

@zzxming zzxming commented Sep 15, 2024

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #61

What is the new behavior?

paste correct format about line-height / text-indent / font-size / font-style / list.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Introduced new attributors for text styling: Font Size, Font Style, Line Height, and Text Indent, enhancing text formatting options in the editor.
    • Added a new attribute for table cells to support list functionalities.
  • Bug Fixes

    • Improved HTML management in the editor to ensure content remains in sync with user edits.
  • Refactor

    • Streamlined code for managing text styles by centralizing update logic and removing outdated configurations.
  • Chores

    • Updated module registration to reflect new styling capabilities and improved organization.

Copy link

coderabbitai bot commented Sep 15, 2024

Walkthrough

The changes introduced in this pull request focus on enhancing the functionality of the Fluent Editor by adding new attributors for text styling, such as font size, font style, line height, and text indent. Additionally, the management of inner HTML in the editor is improved through the introduction of a reactive reference and an update function. Some deprecated configurations related to font settings are removed, indicating a shift towards a more modular and dynamic approach to styling.

Changes

File Path Change Summary
packages/docs/fluent-editor/demos/get-html.vue Added articleRef and updateHTML function for managing inner HTML reactively.
packages/fluent-editor/src/attributors/font-size.ts Introduced SizeStyle attributor for manipulating font size in the Quill editor.
packages/fluent-editor/src/attributors/font-style.ts Introduced FontStyle attributor for managing font family in the Quill editor.
packages/fluent-editor/src/attributors/line-height.ts Introduced LineHeightStyle attributor for managing line height in the Quill editor.
packages/fluent-editor/src/attributors/text-indent.ts Introduced TextIndentStyle attributor for managing text indentation in the Quill editor.
packages/fluent-editor/src/attributors/index.ts Created central export file for text styling attributors.
packages/fluent-editor/src/config.ts Removed FONT_FAMILY_CONFIG and FONT_SIZE_CONFIG constants.
packages/fluent-editor/src/fluent-editor.ts Updated imports and registration of modules; removed old font configurations.
packages/fluent-editor/src/table/table-config.ts Expanded CELL_ATTRIBUTES to include a new 'list' attribute.
packages/fluent-editor/src/lineheight.ts Removed lineheight.ts file, eliminating previous line height management functionality.

Possibly related PRs

  • fix: Fix docs error #62: Involves updating the syntax highlighting configuration in get-html.vue, which relates to managing the inner HTML and integrating syntax highlighting features.

Suggested labels

refactoring

Poem

🐰 In the garden of code, we hop and play,
With new styles and functions, brightening the day.
Font sizes and indents, all neatly aligned,
A tapestry of text, beautifully designed.
So let’s celebrate changes, both big and small,
For in this editor, we’ll style it all! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @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.

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

@github-actions github-actions bot added the bug Something isn't working label Sep 15, 2024
@zzxming zzxming linked an issue Sep 15, 2024 that may be closed by this pull request
@zzxming zzxming marked this pull request as ready for review September 15, 2024 12:21
Copy link

@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

Outside diff range and nitpick comments (1)
packages/fluent-editor/src/fluent-editor.ts (1)

Line range hint 1-161: Reminder: Add tests and update documentation.

The PR checklist indicates that tests for the changes have not been added, and documentation has not been updated in relation to the bug fix. Please ensure that appropriate tests are added to cover the changes and update the relevant documentation to reflect the improvements in the handling of pasted content formatting.

Do you want me to generate the test cases or open a GitHub issue to track these tasks?

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3293006 and c7bfcfd.

Files selected for processing (10)
  • packages/docs/fluent-editor/demos/get-html.vue (3 hunks)
  • packages/fluent-editor/src/attributors/font-size.ts (1 hunks)
  • packages/fluent-editor/src/attributors/font-style.ts (1 hunks)
  • packages/fluent-editor/src/attributors/index.ts (1 hunks)
  • packages/fluent-editor/src/attributors/line-height.ts (1 hunks)
  • packages/fluent-editor/src/attributors/text-indent.ts (1 hunks)
  • packages/fluent-editor/src/config.ts (0 hunks)
  • packages/fluent-editor/src/fluent-editor.ts (3 hunks)
  • packages/fluent-editor/src/lineheight.ts (0 hunks)
  • packages/fluent-editor/src/table/table-config.ts (1 hunks)
Files not reviewed due to no reviewable changes (2)
  • packages/fluent-editor/src/config.ts
  • packages/fluent-editor/src/lineheight.ts
Files skipped from review due to trivial changes (1)
  • packages/fluent-editor/src/attributors/index.ts
Additional comments not posted (11)
packages/fluent-editor/src/attributors/font-size.ts (1)

1-6: LGTM!

The code segment correctly defines a new SizeStyle attributor for the Quill editor, which allows for the manipulation of font size within the editor's content. The attributor is properly associated with the 'font-size' CSS property and configured to operate within the inline scope.

This addition enhances the editor's capabilities by enabling users to adjust font sizes directly through the editor interface, thereby improving the overall text formatting options available to users. The code segment aligns with the PR objective and does not introduce any breaking changes.

packages/fluent-editor/src/attributors/font-style.ts (1)

1-6: LGTM!

The FontStyle attributor is correctly defined using the Parchment library. It maps the font-family CSS property to the font attribute, which is a valid mapping. The scope of the attributor is correctly set to Parchment.Scope.INLINE, which means it will apply to inline elements within the document.

This attributor will allow for more granular control over font styling in the editor, enabling users to specify different font families for selected text.

The code is well-structured and should not introduce any issues.

packages/fluent-editor/src/attributors/line-height.ts (1)

1-6: LGTM!

The LineHeightStyle attributor is correctly defined using the Parchment.StyleAttributor class and is appropriately configured to apply to inline scopes. This addition enhances the styling capabilities of the Quill editor by enabling developers to set and manipulate line-height properties through the editor's API.

The import statements are correct and necessary for the code to function. This change does not introduce any breaking changes to the existing functionality of the editor and improves its flexibility by allowing for more granular control over text styling.

packages/fluent-editor/src/attributors/text-indent.ts (1)

1-6: LGTM!

The TextIndentStyle attributor is correctly implemented and configured:

  • It targets the text-indent CSS property, which is appropriate for controlling text indentation.
  • The scope is set to Parchment.Scope.BLOCK, which is the correct scope for applying text indentation to block-level elements.
  • The attributor is properly exported, making it available for use in other parts of the codebase.

This addition enhances the styling capabilities of the Quill editor by enabling more precise control over text indentation in rich text documents.

packages/fluent-editor/src/table/table-config.ts (1)

24-24: Verify the usage of the new 'list' attribute in the codebase.

The addition of the 'list' attribute to the CELL_ATTRIBUTES constant aligns with the PR objective of fixing formatting issues when pasting content into the editor. This change enhances the flexibility of the table component by allowing list-related properties for table cells.

Please ensure that the new 'list' attribute is properly handled in other parts of the codebase, such as:

  • Parsing and rendering of table cells with the 'list' attribute.
  • Updating any relevant documentation or examples to reflect the new attribute.

Run the following script to verify the usage of the 'list' attribute:

Verification successful

The 'list' attribute is properly integrated and used throughout the codebase.

The addition of the 'list' attribute to the CELL_ATTRIBUTES constant is consistent with its usage in various parts of the codebase. It is being used for list-related operations in table cells, including formatting, handling, and clipboard operations. The implementation supports different types of lists (bullet, ordered, check) and their interactions with other formatting options.

However, it's recommended to update the documentation to include information about the new 'list' attribute for table cells, as no occurrences were found in markdown files.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the 'list' attribute in the codebase.

# Test 1: Search for the 'list' attribute usage in TypeScript files.
# Expect: Occurrences of the 'list' attribute being used or referenced.
rg --type ts -A 5 $'\'list\''

# Test 2: Search for the 'list' attribute in the documentation files.
# Expect: Occurrences of the 'list' attribute in the documentation.
fd -e md -x rg -A 5 $'\'list\''

Length of output: 10071

packages/docs/fluent-editor/demos/get-html.vue (4)

38-38: LGTM!

The introduction of articleRef using ref<HTMLElement>() is a good way to manage the DOM element reactively. It can be used to update the content of the element more effectively.


39-43: LGTM!

The updateHTML function is a good addition that encapsulates the logic for updating the inner HTML of the referenced element. It enhances code maintainability and readability by providing a centralized update logic.

The check for articleRef.value ensures that the update is performed only when the element is available, avoiding potential errors.


82-82: LGTM!

Utilizing updateHTML inside the onMounted lifecycle hook is a good practice. It ensures that the initial content of the editor is displayed correctly and maintains consistency with the rest of the code that uses updateHTML for updates.


85-85: LGTM!

Utilizing updateHTML inside the text-change event listener is a good practice. It ensures that the displayed content remains in sync with the editor's state whenever the content changes. This maintains consistency with the rest of the code that uses updateHTML for updates.

packages/fluent-editor/src/fluent-editor.ts (2)

24-24: Imports align with the PR objectives.

The newly added imports for LineHeightStyle, SizeStyle, FontStyle, and TextIndentStyle from ./attributors suggest a restructuring of how styles are managed within the editor. These attributors are likely related to handling text styles and attributes, which aligns with the PR objectives of ensuring that the pasted content retains the correct formats for various text properties.


148-156: Format registrations align with the PR objectives.

The registration of various formats, including the newly added font, size, line-height, and text-indent, indicates a reorganization of how these formats are registered within the Quill editor. These newly registered formats are likely related to the newly imported attributors, which suggests a refinement in the handling of text styles and attributes. The changes align with the PR objectives of improving the user experience by ensuring that pasted text maintains its intended formatting.

@kagol
Copy link
Member

kagol commented Sep 18, 2024

@zzxming text-indent 未生效,其他的都OK了

@zzxming
Copy link
Collaborator Author

zzxming commented Sep 18, 2024

@zzxming text-indent 未生效,其他的都OK了

text-indent 设置的是首行缩进,文本前后缩进是另外的格式,quill本身也没有实现文本前后的缩进,需要吗?
image

@kagol
Copy link
Member

kagol commented Sep 19, 2024

@zzxming text-indent 未生效,其他的都OK了

text-indent 设置的是首行缩进,文本前后缩进是另外的格式,quill本身也没有实现文本前后的缩进,需要吗? image

了解,我觉得不着急,Word 粘贴本身就比较复杂,后续根据业务需求再逐渐完善吧

@kagol kagol merged commit aef125e into opentiny:main Sep 19, 2024
2 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Oct 25, 2024
13 tasks
This was referenced Nov 15, 2024
@zzxming zzxming deleted the fix-word-paste branch December 6, 2024 12:12
@coderabbitai coderabbitai bot mentioned this pull request Dec 6, 2024
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 [Bug]: 复制 Word 文档中的内容,部分格式丢失
2 participants