Skip to content

Editable toolbar#8959

Open
tuuuni147 wants to merge 6 commits intoTriliumNext:mainfrom
tuuuni147:editable-toolbar
Open

Editable toolbar#8959
tuuuni147 wants to merge 6 commits intoTriliumNext:mainfrom
tuuuni147:editable-toolbar

Conversation

@tuuuni147
Copy link
Copy Markdown

This is the improved version off #8864
it adds the abillity to edit the Toolbar of the texteditor.

Closes:
#5621

@dosubot dosubot bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Mar 8, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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

  • Toolbar Customization UI: Introduced a new user interface for customizing the classic editor toolbar, allowing users to drag, reorder, add, and remove toolbar items.
  • Drag-and-Drop Functionality: Implemented drag-and-drop capabilities for managing toolbar items, including adding separators and grouping items.
  • Dynamic Toolbar Configuration: Modified the toolbar build process to dynamically load and apply custom toolbar configurations saved by the user.
  • Internationalization Support: Added new translation keys to support the text and labels used within the toolbar customization feature.
  • Persistence of Settings: Integrated a new option, textNoteToolbarConfig, to store the user's custom toolbar layout persistently.

🧠 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
  • apps/client/src/translations/en/translation.json
    • Added new translation keys for the toolbar customization feature.
  • apps/client/src/widgets/type_widgets/options/text_notes.tsx
    • Integrated the new ToolbarCustomization component into the text note settings.
  • apps/client/src/widgets/type_widgets/options/toolbar_customization.css
    • Created CSS styles to support the new toolbar customization user interface.
  • apps/client/src/widgets/type_widgets/options/toolbar_customization.tsx
    • Implemented the React component for the editable toolbar, including drag-and-drop functionality.
  • apps/client/src/widgets/type_widgets/text/toolbar.ts
    • Updated toolbar configuration logic to support custom editable toolbars and defined related types and default items.
  • apps/server/src/routes/api/options.ts
    • Registered the new textNoteToolbarConfig option for API access.
  • apps/server/src/services/options_init.ts
    • Initialized the textNoteToolbarConfig option with a default empty value.
  • packages/commons/src/lib/options_interface.ts
    • Extended the OptionDefinitions interface to include textNoteToolbarConfig.
Activity
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +230 to +234
.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);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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

Comment on lines +496 to +498
{pending.map((item, idx) => (
<ToolbarRow
key={idx}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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.

Comment on lines +94 to +139
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"
];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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.

@tuuuni147
Copy link
Copy Markdown
Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This component is quite large and handles a lot of complex logic, including state management, various mutations, and drag-and-drop functionality. To improve readability and maintainability, consider extracting the drag-and-drop logic into a dedicated custom hook, for example useToolbarDragAndDrop.


const usedCommands = collectUsed(pending);
const availableCommands = ALL_COMMANDS.filter((cmd) => !usedCommands.has(cmd));
const hasChanges = JSON.stringify(pending) !== JSON.stringify(parseConfig(configStr));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant