@@ -60,15 +60,30 @@ const COMMA_FIX_DEBOUNCE_MS = 800;
6060const CURSOR_TRIGGER_DEBOUNCE_MS = 50 ;
6161const HINT_CSS_CLASS = 'json-editor-value-hint' ;
6262
63- // Injected once — never removed. Shared across all editor instances.
64- if ( typeof document !== 'undefined' ) {
65- const id = 'json-editor-hint-style' ;
66- if ( ! document . getElementById ( id ) ) {
67- const style = document . createElement ( 'style' ) ;
68- style . id = id ;
69- style . textContent = `.${ HINT_CSS_CLASS } { color: var(--mantine-color-gray-5); font-style: italic; }` ;
70- document . head . appendChild ( style ) ;
63+ // Dynamic hint styles — each unique hint text gets a CSS class with ::after content.
64+ // Monaco 0.55 doesn't support `after.content` in decorations, so we use
65+ // `afterContentClassName` with CSS `::after` pseudo-elements instead.
66+ let hintStyleEl : HTMLStyleElement | null = null ;
67+ let hintClassCounter = 0 ;
68+ const hintClassMap = new Map < string , string > ( ) ;
69+
70+ function getHintClassName ( hintText : string ) : string {
71+ let cls = hintClassMap . get ( hintText ) ;
72+ if ( cls ) return cls ;
73+
74+ cls = `${ HINT_CSS_CLASS } -${ hintClassCounter ++ } ` ;
75+ hintClassMap . set ( hintText , cls ) ;
76+
77+ if ( typeof document !== 'undefined' ) {
78+ if ( ! hintStyleEl ) {
79+ hintStyleEl = document . createElement ( 'style' ) ;
80+ hintStyleEl . id = 'json-editor-hint-styles' ;
81+ document . head . appendChild ( hintStyleEl ) ;
82+ }
83+ const escaped = hintText . replace ( / \\ / g, '\\\\' ) . replace ( / " / g, '\\"' ) ;
84+ hintStyleEl . textContent += `.${ cls } ::after { content: "${ escaped } "; color: var(--mantine-color-gray-5); font-style: italic; pointer-events: none; }\n` ;
7185 }
86+ return cls ;
7287}
7388
7489const EDITOR_OPTIONS : import ( 'monaco-editor' ) . editor . IStandaloneEditorConstructionOptions =
@@ -309,11 +324,7 @@ export const JsonEditorView = ({
309324 getEmptyValueHints ( monaco , model , autocompleteContext ) . map ( ( h ) => ( {
310325 range : h . range ,
311326 options : {
312- after : {
313- content : h . hint ,
314- inlineClassName : HINT_CSS_CLASS ,
315- cursorStops : monaco . editor . InjectedTextCursorStops . None ,
316- } ,
327+ afterContentClassName : getHintClassName ( h . hint ) ,
317328 } ,
318329 } ) )
319330 ) ;
0 commit comments