Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a highly anticipated feature that allows users to personalize their text editor experience by providing a fully editable toolbar. It empowers users to tailor the editor's interface to their specific workflow by rearranging, adding, or removing toolbar elements, thereby enhancing usability and efficiency. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces an excellent new feature allowing users to customize the text editor's toolbar. The implementation is comprehensive, featuring a drag-and-drop interface for reordering toolbar items. I have identified a few areas for improvement related to CSS compatibility, React best practices for list rendering, and code duplication, which could enhance the maintainability and robustness of the new functionality.
| .toolbar-trash.active { | ||
| background: color-mix(in srgb, var(--danger-text-color, #dc3545) 12%, transparent); | ||
| color: var(--danger-text-color, #dc3545); | ||
| border-color: var(--danger-text-color, #dc3545); | ||
| } |
There was a problem hiding this comment.
The color-mix() CSS function is a modern feature with support limited to recent browser versions (e.g., Chrome 111+, Firefox 113+). Depending on the target Electron/Chromium version for this project, this might lead to inconsistent styling. For broader compatibility, you might consider using rgba() or hex colors with alpha transparency. For instance, background: color-mix(in srgb, var(--danger-text-color, #dc3545) 12%, transparent); could be replaced with background: #dc35451f; (which corresponds to ~12% opacity).
| {pending.map((item, idx) => ( | ||
| <ToolbarRow | ||
| key={idx} |
There was a problem hiding this comment.
Using the array index as a key for list items is not recommended for lists that can be reordered, as is the case with this drag-and-drop interface. This can lead to performance issues and state management bugs. It would be better to use a stable, unique identifier for each item.
I suggest assigning a unique ID to each toolbar item when it's loaded into the pending state and using that ID as the key. This applies to both the main list of toolbar items here and the nested list of items within a group (line 689). This will ensure React can correctly track, update, and reorder the components efficiently.
| export const DEFAULT_CLASSIC_TOOLBAR_ITEMS: ToolbarItem[] = [ | ||
| "heading", | ||
| "fontSize", | ||
| "|", | ||
| "bold", | ||
| "italic", | ||
| { | ||
| ...TEXT_FORMATTING_GROUP, | ||
| items: ["underline", "strikethrough", "|", "superscript", "subscript", "|", "kbd"] | ||
| }, | ||
| "formatPainter", | ||
| "|", | ||
| "fontColor", | ||
| "fontBackgroundColor", | ||
| "removeFormat", | ||
| "|", | ||
| "bulletedList", | ||
| "numberedList", | ||
| "todoList", | ||
| "|", | ||
| "blockQuote", | ||
| "admonition", | ||
| "insertTable", | ||
| "|", | ||
| "code", | ||
| "codeBlock", | ||
| "|", | ||
| "footnote", | ||
| { | ||
| label: "Insert", | ||
| icon: "plus", | ||
| items: ["imageUpload", "|", "link", "bookmark", "internallink", "includeNote", "|", "specialCharacters", "emoji", "math", "mermaid", "horizontalLine", "pageBreak", "dateTime"] | ||
| }, | ||
| "|", | ||
| { | ||
| label: "Alignment", | ||
| icon: "alignLeft", | ||
| items: ["alignment:left", "alignment:center", "alignment:right", "|", "alignment:justify"] | ||
| }, | ||
| "outdent", | ||
| "indent", | ||
| "|", | ||
| "insertTemplate", | ||
| "markdownImport", | ||
| "cuttonote" | ||
| ]; |
There was a problem hiding this comment.
The new DEFAULT_CLASSIC_TOOLBAR_ITEMS constant is a great addition for clarity. However, it almost entirely duplicates the toolbar configuration array inside the existing buildClassicToolbar function. This introduces code duplication and a potential for them to get out of sync.
To improve maintainability, I suggest refactoring buildClassicToolbar to use this new DEFAULT_CLASSIC_TOOLBAR_ITEMS constant as its source of truth.
Additionally, I noticed a small inconsistency in the icon for the "Alignment" group. Here it's "alignLeft", but in buildAlignmentToolbar (used by buildClassicToolbar) it's an imported SVG string (IconAlignCenter). It would be good to make these consistent.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a highly requested feature: a customizable toolbar for the classic text editor. The implementation includes a new UI for customization with drag-and-drop support, new translation strings, and updates to the options system to store the custom configuration. The code is well-structured, but I've identified a few areas for improvement regarding performance, maintainability, and code duplication in the new ToolbarCustomization component and the existing toolbar building logic. My review comments provide specific suggestions to address these points.
| return used; | ||
| } | ||
|
|
||
| export default function ToolbarCustomization() { |
There was a problem hiding this comment.
|
|
||
| const usedCommands = collectUsed(pending); | ||
| const availableCommands = ALL_COMMANDS.filter((cmd) => !usedCommands.has(cmd)); | ||
| const hasChanges = JSON.stringify(pending) !== JSON.stringify(parseConfig(configStr)); |
There was a problem hiding this comment.
The parseConfig function is called multiple times on each render (e.g., in the hasChanges check and handleDiscard). This involves JSON.parse, which can be inefficient for large configuration strings. Consider memoizing the result of parseConfig(configStr) using useMemo at the beginning of the component to avoid these redundant computations.
| "cuttonote" | ||
| ]; | ||
|
|
||
| export function buildClassicToolbar(multilineToolbar: boolean) { |
There was a problem hiding this comment.
This function's implementation is nearly identical to the new DEFAULT_CLASSIC_TOOLBAR_ITEMS constant, creating code duplication. This can lead to maintenance issues and inconsistencies, like the different icon for the 'Alignment' group. Please refactor this function to reuse DEFAULT_CLASSIC_TOOLBAR_ITEMS and resolve the inconsistency.
This is the improved version off #8864
it adds the abillity to edit the Toolbar of the texteditor.
Closes:
#5621