Skip to content
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

feat: replace CodeMirror in side editor with Shiki-based textarea #1698

Merged
merged 4 commits into from
Jun 25, 2024

Conversation

KermanX
Copy link
Member

@KermanX KermanX commented Jun 24, 2024

A breaking change because old custom styles may no longer work.

Pros

  • Reduce bundle size
  • Highlighting is more accurate
  • No CJS problems introduced by CodeMirror
  • Load faster
  • Easier to maintain

Cons

  • Undo/redo functionality becomes weak
  • I have to use word-break: break-all, otherwise the text inside <pre shiki> and <textarea> will be mismatched, because <span>s in <pre shiki> affects the word breaking.

Why not use monaco-editor

  • If monaco-editor is used in the side editor, it has to be loaded in dev, even the user doesn't use {monaco-*} features
  • Kind of too complex. Most of the features aren't useful in the side editor.

Resolve #1391.

Copy link

netlify bot commented Jun 24, 2024

Deploy Preview for slidev ready!

Name Link
🔨 Latest commit 5f87147
🔍 Latest deploy log https://app.netlify.com/sites/slidev/deploys/667993280e72b90008470f5f
😎 Deploy Preview https://deploy-preview-1698--slidev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

` theme: ${JSON.stringify(themeOptionsNames.theme)},`,
` themes: ${JSON.stringify(themeOptionsNames.themes)},`,
' defaultColor: false,',
' ...options,',
Copy link
Member Author

@KermanX KermanX Jun 24, 2024

Choose a reason for hiding this comment

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

Moved here from:

const highlight = (code: string, lang: string, options: Partial<CodeToHastOptions> = {}) => highlighter.codeToHtml(code, {
lang,
theme: typeof themes === 'string'
? themes
: isDark.value
? themes.dark || 'vitesse-dark'
: themes.light || 'vitesse-light',
...options,
})

It now uses Shiki's dual theme feature. I am not sure why it wasn't used.

@antfu antfu changed the title refactor!: replace CodeMirror in side editor with Shiki-based textarea feat: replace CodeMirror in side editor with Shiki-based textarea Jun 25, 2024
@antfu antfu merged commit e8bb770 into slidevjs:main Jun 25, 2024
18 checks passed
@KermanX KermanX mentioned this pull request Jul 23, 2024
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.

RFC: Migrate CodeMirror to Monaco
2 participants