-
Notifications
You must be signed in to change notification settings - Fork 300
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
Conversation
WalkthroughThe 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
Poem
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configuration File (
|
[e2e-test-warn] 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 |
There was a problem hiding this 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 like16px
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 like16px
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 handlenull
orundefined
values forvalue
andpreListValue
. Ensure these edge cases are managed to prevent potential runtime errors. Additionally, add tests to verify the behavior ofgetListValue
in these scenarios.
- Location:
packages/fluent-editor/src/config.ts:192-203
- Suggested Changes:
- Modify
getListValue
to handlenull
orundefined
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
orpreListValue
arenull
orundefined
.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 ifrange
isnull
before accessing its properties, which could lead to potential errors.
- Add a check for
range
beingnull
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.tsLength 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.tsLength 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.tsLength of output: 4449
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
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.
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); | ||
} | ||
}, |
There was a problem hiding this comment.
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?
There was a problem hiding this 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
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
, andcursor
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
, andcursor
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 whenpreListValue
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 requiredtasklist
andtasklistOutside
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/assetsLength 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.scssLength 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
andunchecked
, 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/assetsLength 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/assetsLength 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.scssLength 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
andli.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/assetsLength 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" doneLength 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.scssLength of output: 338
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; |
There was a problem hiding this comment.
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?
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); | ||
} |
There was a problem hiding this comment.
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?
PR
修复任务列表不生效问题。
效果如下:
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
New Features
Bug Fixes
Documentation