feat(editor): add format button to codeblock toolbar#9076
feat(editor): add format button to codeblock toolbar#9076giuxtaposition wants to merge 26 commits intoTriliumNext:mainfrom
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 significant enhancement to the CKEditor5 code block functionality by adding an integrated code formatting button. This feature leverages Prettier to automatically format code within code blocks, improving code readability and consistency directly within the editor. The implementation includes new plugins, commands, and configuration to support various programming and markup languages, making the code editing experience more robust and user-friendly. 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
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 a new 'Format' button to the code block toolbar, leveraging Prettier to format code snippets within the editor. The implementation is well-structured, making good use of dynamic imports for performance and including a comprehensive set of tests. My feedback focuses on a couple of areas for improvement: refining the code extraction logic to better preserve user-inputted formatting, and a refactoring opportunity in the language configuration to enhance maintainability by reducing code duplication.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new feature to format code blocks within the editor, leveraging Prettier for various languages. The implementation includes a FormatterRegistry for managing different formatters, a FormatCodeblockCommand to execute the formatting logic, and a UI button to trigger the action. The changes are well-structured, integrate smoothly with the existing CKEditor 5 architecture, and are accompanied by comprehensive unit tests, ensuring the reliability and correctness of the new functionality.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new 'Format' button for code blocks in the editor, leveraging Prettier.js for code formatting. The implementation is well-structured, using a plugin architecture with a command, a singleton registry for formatters, and dynamic imports for Prettier plugins to optimize bundle size. The changes also include comprehensive unit tests. My review includes a few suggestions to improve correctness and robustness, particularly regarding XML formatting, text extraction logic to prevent re-runs, and test stability.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new feature to format code blocks within the CKEditor5 instance, leveraging Prettier for various languages. The implementation includes a new FormatCodeblockButton plugin, a FormatCodeblockCommand, and a FormatterRegistry to manage different code formatters. New SVG icons and language constants are also added. The changes are well-tested with comprehensive unit tests covering various scenarios, including supported/unsupported languages and different code types.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
… button test Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…s more complex than I thought
…lback and add types The CKEditor notification warning handler had its parameters reversed (data, evt) instead of (evt, data), causing it to read title/message from EventInfo and call .stop() on NotificationShowEventData. Added proper types (EventInfo, NotificationShowEventData) to prevent future regressions.
8bed3a1 to
47becfb
Compare
47becfb to
09fd1bd
Compare
|
@eliandoran Sorry for the many PRs! I recently migrated my notes to Trilium and have been adding a few features I missed from my previous setup lol There is currently a failing test. I’m not sure if it ever passed, since the ckeditor5 package tests weren’t being run before my changes. Let me know if I need to fix it or delete it. For the code formatter, I followed a strategy pattern so we can easily add additional formatters alongside Prettier in the future! |
eliandoran
left a comment
There was a problem hiding this comment.
Seems promising, but before this can be merged we need to:
- On my side: Check the impact on the delivery size. I will trigger a nightly build to see if the size increase is acceptable.
- On your side: Handling the actual formatting should not be the responsibility of the CKEditor plugin. The reasoning is that we might want to introduce the same for code notes, not just code blocks (or even different editors if we ever get to that). So move the formatting part into the client and provide an API to determine if formatting is enabled.
- Documentation also need to be updated to reflect this feature. A general mention of what languages are supported and what not and that it doesn't work if the language is set to auto.
- add missing Template plugin from ckeditor5-premium-features - add afterEach cleanup to destroy editor and remove DOM element - fix TypeScript error by replacing optional chaining with non-null assertion on toolbar
d128706 to
1f333b8
Compare
…instead of a ckeditor5 plugin
1f333b8 to
16fe432
Compare
2b5f187 to
e5d7245
Compare
…nt phantom softBreak
…erations when pressing format button many times
…roperty shorthand
d284128 to
ff0028a
Compare
ff0028a to
813c7a5
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a code formatting feature for code blocks in the editor, powered by Prettier. The implementation is well-structured, with a clear separation between the generic formatter registry and the Prettier-specific implementation. The new CKEditor plugin, command, and button are correctly integrated, and the feature is well-tested and documented. I've found a significant issue with how Prettier plugins are being dynamically imported, which would likely prevent the feature from working. My review includes suggestions to fix this.
Prettier's ESM plugins explicitly re-export everything as named exports |
No description provided.