Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(fluent-editor): fix tasklist format #1845

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

Merged
merged 1 commit into from
Aug 7, 2024
Merged

Conversation

kagol
Copy link
Member

@kagol kagol commented Aug 6, 2024

PR

修复任务列表不生效问题。

效果如下:

tasklist

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: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Enhanced task list management within the Fluent Editor with integrated styles.
    • New functionality for seamless list formatting that interacts with table columns.
  • Bug Fixes

    • Improved handling of list state values for better task item management.
  • Documentation

    • Updated SCSS for task lists to enhance visual feedback and user experience.

@kagol kagol added the bug Something isn't working label Aug 6, 2024
Copy link

coderabbitai bot commented Aug 6, 2024

Walkthrough

The recent changes enhance the Fluent Editor by integrating task list functionality and improving list formatting within the editor. New SCSS styles for task management have been added, along with logic for handling list states through a newly introduced function. Additionally, the ability to format lists in conjunction with table elements has been implemented, significantly improving the user experience and task management capabilities of the editor.

Changes

Files Change Summary
packages/fluent-editor/src/assets/*.scss Added task list styles by uncommenting relevant lines and defining mixins for tasklist and tasklistOutside, enhancing task management capabilities.
packages/fluent-editor/src/config.ts Introduced getListValue function to manage list states based on current and previous values, enhancing list behavior logic.
packages/fluent-editor/src/fluent-editor.ts Added list method in registerModules to apply list formatting in conjunction with table columns, improving formatting capabilities within the editor.

Poem

🐰 In a world of tasks and lists so neat,
A sprinkle of code makes it all complete.
With styles anew, the editor sings,
A hop and a jump, oh, the joy it brings!
So gather 'round, let creativity flow,
With each little change, our skills will grow! 🌟


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

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

github-actions bot commented Aug 6, 2024

[e2e-test-warn]
The component to be tested is missing.

The title of the Pull request should look like "fix(vue-renderless): [action-menu, alert] fix xxx bug".

Please make sure you've read our contributing guide

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: 2

Outside diff range, codebase verification and nitpick comments (9)
packages/fluent-editor/src/assets/tasklist.scss (5)

1-14: Ensure consistency in style definitions.

The styles for .ql-ui elements are consistent, but consider using variables for repeated values like 16px and #adb0b8 for better maintainability.

@mixin tasklist {
  $ui-size: 16px;
  $ui-color: #adb0b8;

  li.checked > .ql-ui,
  li.unchecked > .ql-ui {
    display: inline-block;
    width: $ui-size;
    height: $ui-size;
    line-height: 14px;
    text-align: right;
    margin-left: -26px;
    margin-right: 10px;
    border: 1px solid $ui-color;
    color: $ui-color;
    cursor: pointer;
  }
}

16-22: Consider using variables for colors and transition times.

Using variables for colors and transition times can improve maintainability and readability.

li.checked > .ql-ui {
  border: 1px solid #5e7ce0;
  background: #5e7ce0 url('data:image/svg+xml;base64,...');
  transition: all 0.3s ease-in-out;
}

29-39: Use comments in English for better readability.

The comment // 样式重置 is in Chinese. Consider using English comments for better readability by a wider audience.

// Style reset
li.checked,
li.unchecked {
  display: block;
  width: initial;
  height: initial;
  margin-left: initial;
  color: initial;
  border: initial;
  cursor: initial;
}

52-65: Ensure consistency in style definitions.

Similar to the tasklist mixin, consider using variables for repeated values like 16px and #adb0b8 for better maintainability.

@mixin tasklistOutside {
  $ui-size: 16px;
  $ui-color: #adb0b8;

  li.checked::before,
  li.unchecked::before {
    display: inline-block;
    width: $ui-size;
    height: $ui-size;
    text-align: right;
    margin-left: -26px;
    border: 1px solid $ui-color;
    content: '';
    position: absolute;
    top: 1px;
    margin-right: 0.7em;
  }
}

67-72: Consider using variables for colors.

Using variables for colors can improve maintainability and readability.

li.checked::before {
  border: 1px solid #5e7ce0;
  background: #5e7ce0 url('data:image/svg+xml;base64,...');
}
packages/fluent-editor/src/config.ts (2)

192-203: Improve code readability.

Consider adding comments to explain the logic, especially the conditions and the purpose of the function.

/**
 * Determines the current list value based on the previous list value.
 * @param value - The current value.
 * @param preListValue - The previous list value.
 * @returns The current list value.
 */
export function getListValue(value, preListValue) {
  let curListValue = value;
  if (preListValue && preListValue === value) {
    curListValue = false;
  } else if (value === 'check') {
    if (preListValue === 'checked' || preListValue === 'unchecked') {
      curListValue = false;
    } else {
      curListValue = 'unchecked';
    }
  }
  return curListValue;
}

192-203: Ensure edge cases are handled.

The function getListValue does not explicitly handle null or undefined values for value and preListValue. Ensure these edge cases are managed to prevent potential runtime errors. Additionally, add tests to verify the behavior of getListValue in these scenarios.

  • Location: packages/fluent-editor/src/config.ts:192-203
  • Suggested Changes:
    • Modify getListValue to handle null or undefined values.
    • Add tests to cover these edge cases.
Analysis chain

Ensure edge cases are handled.

The function logic seems correct, but ensure that all edge cases are handled, such as when value or preListValue are null or undefined.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify edge cases for the function `getListValue`.

# Test: Ensure the function handles null and undefined values correctly.
rg --type ts -A 5 $'getListValue'

Length of output: 1854


Script:

#!/bin/bash
# Retrieve the complete implementation of the `getListValue` function
ast-grep --lang typescript --pattern $'function getListValue($_, $_) {
  $$$
}' 

# Search for tests related to `getListValue`
rg --type ts 'getListValue'

Length of output: 1382

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

57-90: Improve code readability.

Consider adding comments to explain the logic, especially the conditions and the purpose of the method.

list: function (value) {
  const range = this.quill.getSelection();
  const formats = this.quill.getFormat(range);
  const preListValue = Array.isArray(formats.list) ? formats.list[0]?.value : formats.list?.value;
  const curListValue = getListValue(value, preListValue);

  // If the selection range includes table columns, apply list formatting before and after the table.
  const lines = this.quill.getLines(range.index, range.length);
  const tableCols = lines.filter((line) => line.statics.blotName === 'table-col' && !line.prev);
  if (tableCols.length) {
    let start = range.index;
    tableCols.forEach((item, index) => {
      const table = item.domNode.closest('table.quill-better-table');
      const tableBlot = Quill.find(table);
      const tableLength = tableBlot.length();
      const tableStart = this.quill.getIndex(item);
      const tableEnd = tableStart + tableLength;
      const beforeTableRangeLength = tableStart - start;

      // Apply list formatting before the table.
      this.quill.setSelection(start, beforeTableRangeLength, Quill.sources.SILENT);
      this.quill.format('list', curListValue, Quill.sources.USER);
      table.parentNode.classList.remove('quill-better-table-selected');

      // Set the start for the next selection range.
      start = tableEnd;
      if (index === tableCols.length - 1) {
        // Apply list formatting after the table.
        this.quill.setSelection(tableEnd, range.index + range.length - tableEnd);
        this.quill.format('list', curListValue, Quill.sources.USER);
      }
    });
  } else {
    this.quill.format('list', curListValue, Quill.sources.USER);
  }
},

57-90: Ensure edge cases are handled.

The method logic seems correct, but ensure that all edge cases are handled, such as when the selection range is null. Currently, the method does not check if range is null before accessing its properties, which could lead to potential errors.

  • Add a check for range being null before accessing its properties.
Analysis chain

Ensure edge cases are handled.

The method logic seems correct, but ensure that all edge cases are handled, such as when the selection range is null or when there are no table columns.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify edge cases for the method `list`.

# Test: Ensure the method handles null selection range and no table columns correctly.
rg --type ts -A 5 $'list'

Length of output: 287505


Script:

#!/bin/bash
# Description: Verify edge cases for the method `list` within the specified file and lines.

# Test: Ensure the method handles null selection range and no table columns correctly.
rg --type ts --line-number --context 5 --max-count 1 'list: function' packages/fluent-editor/src/fluent-editor.ts

Length of output: 739


Script:

#!/bin/bash
# Description: Extract the complete implementation of the `list` method.

# Extract the `list` method implementation from `packages/fluent-editor/src/fluent-editor.ts`
rg --type ts --line-number --context 30 'list: function' packages/fluent-editor/src/fluent-editor.ts

Length of output: 3089


Script:

#!/bin/bash
# Description: Extract the complete implementation of the `list` method.

# Extract the `list` method implementation from `packages/fluent-editor/src/fluent-editor.ts`
rg --type ts --line-number --context 50 'list: function' packages/fluent-editor/src/fluent-editor.ts

Length of output: 4449

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b2cfcfb and 582efd8.

Files selected for processing (4)
  • packages/fluent-editor/src/assets/editor.scss (3 hunks)
  • packages/fluent-editor/src/assets/tasklist.scss (1 hunks)
  • packages/fluent-editor/src/config.ts (1 hunks)
  • packages/fluent-editor/src/fluent-editor.ts (2 hunks)
Additional comments not posted (3)
packages/fluent-editor/src/assets/editor.scss (3)

2-2: LGTM! Task list styles are now included.

The import statement for tasklist has been uncommented, which is necessary for task list functionality.


209-210: LGTM! Task list mixin included within the editor.

The tasklist mixin has been included within the .ql-editor class, which is necessary for task list functionality.


359-360: LGTM! Task list styles for outside the editor included.

The tasklistOutside mixin has been included at the end of the file, which is necessary for task list functionality outside the editor.

Comment on lines +57 to +90
list: function (value) {
const range = this.quill.getSelection();
const formats = this.quill.getFormat(range);
const preListValue = Array.isArray(formats.list) ? formats.list[0]?.value : formats.list?.value;
const curListValue = getListValue(value, preListValue);
// 如果设置list的选区中有表格,判断第一个table-col位置,将表格前的内容设置为list格式
const lines = this.quill.getLines(range.index, range.length);
const tableCols = lines.filter((line) => line.statics.blotName === 'table-col' && !line.prev);
if (tableCols.length) {
let start = range.index;
// 遍历table-col群组,以之获取表格,将表格前选区设置为对应list格式
tableCols.forEach((item, index) => {
const table = item.domNode.closest('table.quill-better-table');
const tableBlot = Quill.find(table);
const tableLength = tableBlot.length();
const tableStart = this.quill.getIndex(item);
const tableEnd = tableStart + tableLength;
const beforeTableRangeLength = tableStart - start;
// 在表格前设置列表
this.quill.setSelection(start, beforeTableRangeLength, Quill.sources.SILENT);
this.quill.format('list', curListValue, Quill.sources.USER);
table.parentNode.classList.remove('quill-better-table-selected');
// 当前表格末尾为下一个选取的开始
start = tableEnd;
if (index === tableCols.length - 1) {
// 将最后一个表格之后所有选区内容设置list格式
this.quill.setSelection(tableEnd, range.index + range.length - tableEnd);
this.quill.format('list', curListValue, Quill.sources.USER);
}
});
} else {
this.quill.format('list', curListValue, Quill.sources.USER);
}
},
Copy link

Choose a reason for hiding this comment

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

Add unit tests for the new method.

The method list should have corresponding unit tests to ensure its correctness.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

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: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b2cfcfb and 582efd8.

Files selected for processing (4)
  • packages/fluent-editor/src/assets/editor.scss (3 hunks)
  • packages/fluent-editor/src/assets/tasklist.scss (1 hunks)
  • packages/fluent-editor/src/config.ts (1 hunks)
  • packages/fluent-editor/src/fluent-editor.ts (2 hunks)
Additional comments not posted (13)
packages/fluent-editor/src/assets/tasklist.scss (8)

1-14: Ensure consistency in UI elements.

The styles for list items ensure that the UI elements are consistent and clickable. The use of inline-block, width, height, and cursor properties is appropriate.


16-22: Verify the SVG data URL.

The SVG data URL for the checked state is embedded directly in the SCSS. Ensure that the SVG is correct and renders properly in all supported browsers.


24-27: Reset styles for pseudo-elements.

The pseudo-elements for both checked and unchecked states are reset appropriately.


29-39: Reset styles for list items.

The mixin resets styles for list items to ensure no inherited styles affect the task list.


41-49: Reset styles for UI elements.

The mixin resets styles for the UI elements within list items.


52-65: Ensure consistency in UI elements.

The styles for list items ensure that the UI elements are consistent and clickable. The use of inline-block, width, height, and cursor properties is appropriate.


67-72: Verify the SVG data URL.

The SVG data URL for the checked state is embedded directly in the SCSS. Ensure that the SVG is correct and renders properly in all supported browsers.


74-77: Reset styles for UI elements.

The mixin resets styles for the UI elements within list items.

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

192-203: Ensure the logic handles all edge cases.

The function getListValue appears to handle various cases for list values effectively. However, ensure that all edge cases are covered, especially when preListValue is undefined or null.

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

57-89: Ensure the logic handles all edge cases.

The method list appears to handle various cases for list formatting effectively. However, ensure that all edge cases are covered, especially when dealing with table columns.

packages/fluent-editor/src/assets/editor.scss (3)

2-2: Verify the existence and correct reference of the imported file.

Ensure that the ./tasklist file exists and is correctly referenced to avoid import errors.

Verification successful

The import statement is valid and the necessary mixins are defined.

  • The file tasklist.scss exists in the specified path.
  • The tasklist.scss file contains the required tasklist and tasklistOutside mixins.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of the `tasklist` file.

# Test: Check if the `tasklist` file exists in the specified path.
fd 'tasklist.scss' ./packages/fluent-editor/src/assets

Length of output: 104


Script:

#!/bin/bash
# Description: Verify the contents of the `tasklist.scss` file for required mixins.

# Test: Check if the `tasklist.scss` file contains the `tasklist` and `tasklistOutside` mixins.
rg '@mixin (tasklist|tasklistOutside)' ./packages/fluent-editor/src/assets/tasklist.scss

Length of output: 133


209-210: Verify the correct definition and usage of the mixin.

Ensure that the tasklist mixin is correctly defined and does not cause any conflicts within the .ql-editor class.

Verification successful

Verify the correct definition and usage of the mixin.

Ensure that the tasklist mixin is correctly defined and does not cause any conflicts within the .ql-editor class.


Verify the correct definition and usage of the mixin.

Ensure that the tasklist mixin is correctly defined and does not cause any conflicts within the .ql-editor class.


The tasklist mixin is correctly defined and does not cause any conflicts.

The mixin includes styles for list items with classes checked and unchecked, ensuring they have specific display, size, margin, and border properties, which should integrate well within the .ql-editor class.

  • The tasklist mixin is defined in ./packages/fluent-editor/src/assets/tasklist.scss.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correct definition and usage of the `tasklist` mixin.

# Test: Search for the definition of the `tasklist` mixin. Expect: The mixin is correctly defined.
rg --type scss '@mixin tasklist' ./packages/fluent-editor/src/assets

Length of output: 99


Script:

#!/bin/bash
# Description: Verify the correct definition and usage of the `tasklist` mixin.

# Test: Search for the definition of the `tasklist` mixin using a corrected file type.
rg '@mixin tasklist' ./packages/fluent-editor/src/assets

Length of output: 201


Script:

#!/bin/bash
# Description: Check the content of the `tasklist` mixin definition.

# Test: Display the content of the `tasklist` mixin.
rg -A 10 '@mixin tasklist' ./packages/fluent-editor/src/assets/tasklist.scss

Length of output: 588


359-360: Verify the correct definition and usage of the mixin.

Ensure that the tasklistOutside mixin is correctly defined and does not cause any conflicts outside the editor.

Verification successful

The tasklistOutside mixin is correctly defined and implemented.

  • The mixin is located in ./packages/fluent-editor/src/assets/tasklist.scss.
  • It includes styles for li.checked::before and li.unchecked::before.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correct definition and usage of the `tasklistOutside` mixin.

# Test: Search for the definition of the `tasklistOutside` mixin. Expect: The mixin is correctly defined.
rg --type scss '@mixin tasklistOutside' ./packages/fluent-editor/src/assets

Length of output: 106


Script:

#!/bin/bash
# Description: Verify the correct definition and usage of the `tasklistOutside` mixin.

# Step 1: Locate all SCSS files in the specified directory.
scss_files=$(fd -e scss . ./packages/fluent-editor/src/assets)

# Step 2: Search for the definition of the `tasklistOutside` mixin within the located SCSS files.
for file in $scss_files; do
  echo "Searching in $file"
  rg '@mixin tasklistOutside' "$file"
done

Length of output: 4739


Script:

#!/bin/bash
# Description: Extract and display the contents of the `tasklistOutside` mixin.

# Step 1: Extract the contents of the `tasklistOutside` mixin.
rg -A 10 '@mixin tasklistOutside' ./packages/fluent-editor/src/assets/tasklist.scss

Length of output: 338

Comment on lines +192 to +203
export function getListValue(value, preListValue) {
let curListValue = value;
if (preListValue && preListValue === value) {
curListValue = false;
} else if (value === 'check') {
if (preListValue === 'checked' || preListValue === 'unchecked') {
curListValue = false;
} else {
curListValue = 'unchecked';
}
}
return curListValue;
Copy link

Choose a reason for hiding this comment

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

Consider adding unit tests for getListValue.

Unit tests should be added to ensure the function behaves as expected in different scenarios.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Comment on lines +57 to +89
list: function (value) {
const range = this.quill.getSelection();
const formats = this.quill.getFormat(range);
const preListValue = Array.isArray(formats.list) ? formats.list[0]?.value : formats.list?.value;
const curListValue = getListValue(value, preListValue);
// 如果设置list的选区中有表格,判断第一个table-col位置,将表格前的内容设置为list格式
const lines = this.quill.getLines(range.index, range.length);
const tableCols = lines.filter((line) => line.statics.blotName === 'table-col' && !line.prev);
if (tableCols.length) {
let start = range.index;
// 遍历table-col群组,以之获取表格,将表格前选区设置为对应list格式
tableCols.forEach((item, index) => {
const table = item.domNode.closest('table.quill-better-table');
const tableBlot = Quill.find(table);
const tableLength = tableBlot.length();
const tableStart = this.quill.getIndex(item);
const tableEnd = tableStart + tableLength;
const beforeTableRangeLength = tableStart - start;
// 在表格前设置列表
this.quill.setSelection(start, beforeTableRangeLength, Quill.sources.SILENT);
this.quill.format('list', curListValue, Quill.sources.USER);
table.parentNode.classList.remove('quill-better-table-selected');
// 当前表格末尾为下一个选取的开始
start = tableEnd;
if (index === tableCols.length - 1) {
// 将最后一个表格之后所有选区内容设置list格式
this.quill.setSelection(tableEnd, range.index + range.length - tableEnd);
this.quill.format('list', curListValue, Quill.sources.USER);
}
});
} else {
this.quill.format('list', curListValue, Quill.sources.USER);
}
Copy link

Choose a reason for hiding this comment

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

Consider adding unit tests for list.

Unit tests should be added to ensure the method behaves as expected in different scenarios.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

@zzcr zzcr merged commit b787761 into dev Aug 7, 2024
7 checks passed
@kagol kagol deleted the kagol/fix-fluent-editor-tasklist branch November 4, 2024 03:52
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.

2 participants