Skip to content

[6.x] UI Code Editor #11856

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 12 commits into from
Jun 10, 2025
Merged

[6.x] UI Code Editor #11856

merged 12 commits into from
Jun 10, 2025

Conversation

duncanmcclean
Copy link
Member

@duncanmcclean duncanmcclean commented Jun 9, 2025

This pull request extracts our CodeMirror implementation out of the Code Fieldtype, into a dedicated <CodeEditor> UI component, allowing it to be re-used by third-party developers.

I considered re-implementing the code editor using Monaco (the editor powering VS Code), but decided against it due to the functionality we'd have to remove/re-map, and the additional dependencies we'd need to add the Antlers Textmate grammar.

Usage

<CodeEditor mode="php" v-model:model-value="codeSnippet" />

Copy link
Member

@jasonvarga jasonvarga left a comment

Choose a reason for hiding this comment

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

I think the toolbar, fullscreen mode, mode selector, etc should probably all be part of the component.

If someone has a need to use the code editor on its own, they'll probably want to use those.

The toolbar being outside in the fieldtype is a bit awkward. There's no buttons except for the mode selector. If we wanted to add buttons later, it would make sense to be in the editor itself, then we'd have a weird situation where some buttons are in the editor and some outside. Let's just make it part of the editor itself.

We can probably expose v-model for the code itself, and v-model:mode for the mode.

<CodeEditor
  :allow-mode-selection="config.mode_selectable"
  :value="value.code"
  :mode="value.mode"
  @update:value="codeUpdated"
  @update:mode="modeUpdated"
/>

Happy for this to be pushed back on though.

@duncanmcclean
Copy link
Member Author

Yeah, makes sense!

@jasonvarga jasonvarga merged commit 52c7d6d into ui Jun 10, 2025
17 of 18 checks passed
@jasonvarga jasonvarga deleted the ui-code-editor branch June 10, 2025 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants