Skip to content

fix(monaco): add high-contrast theme support#1099

Closed
adarsh-priydarshi-5646 wants to merge 1 commit into
shikijs:mainfrom
adarsh-priydarshi-5646:fix/monaco-high-contrast-theme-support
Closed

fix(monaco): add high-contrast theme support#1099
adarsh-priydarshi-5646 wants to merge 1 commit into
shikijs:mainfrom
adarsh-priydarshi-5646:fix/monaco-high-contrast-theme-support

Conversation

@adarsh-priydarshi-5646

Copy link
Copy Markdown

Description

This PR fixes high-contrast theme support in shikiToMonaco by properly detecting and configuring Monaco editor's base theme for high-contrast themes.

Problem:
When using high-contrast themes (like github-dark-high-contrast or github-light-high-contrast) with Monaco editor, the selection foreground color was not being applied correctly. This is because Monaco requires the theme base to be set to hc-black or hc-light for high-contrast mode to work properly, but shikiToMonaco was only using vs and vs-dark.

Solution:

  • Detect high-contrast themes by checking if the theme name contains 'high-contrast' (case-insensitive)
  • Set Monaco base to 'hc-black' for dark high-contrast themes
  • Set Monaco base to 'hc-light' for light high-contrast themes
  • Regular themes continue to use 'vs' (light) and 'vs-dark' (dark) as before

Changes:

  • Modified textmateThemeToMonacoTheme function in /packages/monaco/src/index.ts
  • Added comprehensive test suite in /packages/monaco/test/high-contrast.test.ts with 5 test cases covering:
    • Dark high-contrast themes → hc-black
    • Light high-contrast themes → hc-light
    • Regular dark themes → vs-dark
    • Regular light themes → vs
    • Case-insensitive detection

Linked Issues

Fixes #1081

Additional context

The fix is minimal and backward-compatible. All existing themes continue to work as before, while high-contrast themes now properly enable Monaco's high-contrast mode, making the editor accessible for users who need high-contrast interfaces.

The detection method (checking for "high-contrast" in the theme name) aligns with the existing naming convention used by bundled themes like github-dark-high-contrast and github-light-high-contrast.

- Detect high-contrast themes by checking if theme name contains 'high-contrast'
- Set Monaco base to 'hc-black' for dark high-contrast themes
- Set Monaco base to 'hc-light' for light high-contrast themes
- Add comprehensive tests for high-contrast theme detection

Fixes #1081
@netlify

netlify Bot commented Nov 6, 2025

Copy link
Copy Markdown

Deploy Preview for shiki-next ready!

Name Link
🔨 Latest commit 074ff50
🔍 Latest deploy log https://app.netlify.com/projects/shiki-next/deploys/690c794a09340800082512df
😎 Deploy Preview https://deploy-preview-1099--shiki-next.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 project configuration.

@netlify

netlify Bot commented Nov 6, 2025

Copy link
Copy Markdown

Deploy Preview for shiki-matsu ready!

Name Link
🔨 Latest commit 074ff50
🔍 Latest deploy log https://app.netlify.com/projects/shiki-matsu/deploys/690c794a4bd2430007fa5cbe
😎 Deploy Preview https://deploy-preview-1099--shiki-matsu.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 project configuration.

@codecov

codecov Bot commented Nov 6, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.26%. Comparing base (4bf5be3) to head (074ff50).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1099   +/-   ##
=======================================
  Coverage   88.26%   88.26%           
=======================================
  Files          74       74           
  Lines        3298     3298           
  Branches      948      946    -2     
=======================================
  Hits         2911     2911           
  Misses        344      344           
  Partials       43       43           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@adarsh-priydarshi-5646

Copy link
Copy Markdown
Author

Hi @antfu, I’ve solved this issue and the PR is ready for review and merge.

@antfu

antfu commented Dec 3, 2025

Copy link
Copy Markdown
Member

Why did you close the PR tho?

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.

shikiToMonaco needs to take into account high-contrast themes

2 participants