@@ -127,6 +127,17 @@ export function registerYamlAutocomplete(monaco, schema, options = {}) {
127127 }
128128 case 'template' :
129129 return makeSuggestions ( monaco , rootProps . template ?. properties || { } , range , 'template' ) ;
130+ case 'content-options' : {
131+ const formatDef = context . format
132+ ? defs [ context . format + 'Options' ]
133+ : null ;
134+ const props = formatDef ?. properties || { } ;
135+ return makeSuggestions ( monaco , props , range , 'content-options' ) ;
136+ }
137+ case 'content-charset-item' : {
138+ const props = defs . charsetStyle ?. properties || { } ;
139+ return makeSuggestions ( monaco , props , range , 'content-charset-item' ) ;
140+ }
130141 default :
131142 return { suggestions : [ ] } ;
132143 }
@@ -149,6 +160,30 @@ function detectContext(text, currentIndent) {
149160 if ( lineIndent < currentIndent ) {
150161 if ( trimmed === 'canvas:' ) return { type : 'canvas' } ;
151162 if ( trimmed === 'template:' ) return { type : 'template' } ;
163+
164+ // Check for charset designator (single word key, e.g. "I:")
165+ const isDesignatorKey = trimmed . match ( / ^ \w + : $ / ) ;
166+ if ( isDesignatorKey ) {
167+ for ( let k = i - 1 ; k >= 0 ; k -- ) {
168+ const prev = lines [ k ] ;
169+ const prevTrimmed = prev . trim ( ) ;
170+ if ( ! prevTrimmed || prevTrimmed . startsWith ( '#' ) ) continue ;
171+ const prevIndent = prev . match ( / ^ ( \s * ) / ) [ 1 ] . length ;
172+ if ( prevIndent < lineIndent ) {
173+ if ( prevTrimmed === 'charsets:' ) {
174+ return { type : 'content-charset-item' } ;
175+ }
176+ break ;
177+ }
178+ }
179+ }
180+
181+ if ( trimmed === 'options:' ) {
182+ const parentInfo = findContentParent ( lines , i , lineIndent ) ;
183+ if ( parentInfo ) {
184+ return { type : 'content-options' , format : parentInfo . format } ;
185+ }
186+ }
152187 if ( trimmed === 'fonts:' || trimmed === '- name:' || trimmed . startsWith ( '- name:' ) ) {
153188 return { type : 'font-item' } ;
154189 }
@@ -190,6 +225,32 @@ function detectContext(text, currentIndent) {
190225 return { type : 'unknown' } ;
191226}
192227
228+ function findContentParent ( lines , fromIndex , optionsIndent ) {
229+ let format = null ;
230+ for ( let i = fromIndex - 1 ; i >= 0 ; i -- ) {
231+ const line = lines [ i ] ;
232+ const trimmed = line . trim ( ) ;
233+ if ( ! trimmed || trimmed . startsWith ( '#' ) ) continue ;
234+ const indent = line . match ( / ^ ( \s * ) / ) [ 1 ] . length ;
235+ if ( indent >= optionsIndent ) {
236+ const formatMatch = trimmed . match ( / ^ f o r m a t : \s * ( \w + ) / ) ;
237+ if ( formatMatch ) format = formatMatch [ 1 ] ;
238+ continue ;
239+ }
240+ const typeMatch = trimmed . match ( / ^ - ? \s * t y p e : \s * ( \w + ) / ) ;
241+ if ( typeMatch ) {
242+ if ( typeMatch [ 1 ] === 'content' ) return { format } ;
243+ return null ;
244+ }
245+ if ( indent < optionsIndent ) {
246+ const formatMatch = trimmed . match ( / ^ - ? \s * f o r m a t : \s * ( \w + ) / ) ;
247+ if ( formatMatch ) format = formatMatch [ 1 ] ;
248+ }
249+ if ( indent === 0 ) break ;
250+ }
251+ return null ;
252+ }
253+
193254function suggestValues ( monaco , key , textUntilPosition , schema , defs , elementPropsMap , range , options ) {
194255 const suggestions = [ ] ;
195256
@@ -312,6 +373,16 @@ function findPropertyDef(key, textUntilPosition, schema, defs, elementPropsMap)
312373 }
313374 }
314375
376+ // Check if inside content options or charset item
377+ const optionsContext = detectContentOptionsContext ( lines ) ;
378+ if ( optionsContext === 'charset-item' ) {
379+ const charsetDef = defs . charsetStyle ;
380+ if ( charsetDef ?. properties ?. [ cleanKey ] ) return charsetDef . properties [ cleanKey ] ;
381+ } else if ( optionsContext ) {
382+ const optDef = defs [ optionsContext + 'Options' ] ;
383+ if ( optDef ?. properties ?. [ cleanKey ] ) return optDef . properties [ cleanKey ] ;
384+ }
385+
315386 // Check flex item properties as fallback
316387 if ( defs . flexItemProperties ?. properties ?. [ cleanKey ] ) {
317388 return defs . flexItemProperties . properties [ cleanKey ] ;
@@ -320,6 +391,37 @@ function findPropertyDef(key, textUntilPosition, schema, defs, elementPropsMap)
320391 return null ;
321392}
322393
394+ function detectContentOptionsContext ( lines ) {
395+ for ( let i = lines . length - 2 ; i >= 0 ; i -- ) {
396+ const line = lines [ i ] ;
397+ const trimmed = line . trim ( ) ;
398+ if ( ! trimmed || trimmed . startsWith ( '#' ) ) continue ;
399+ const indent = line . match ( / ^ ( \s * ) / ) [ 1 ] . length ;
400+
401+ // Check for charset designator pattern
402+ if ( trimmed . match ( / ^ \w + : $ / ) ) {
403+ for ( let k = i - 1 ; k >= 0 ; k -- ) {
404+ const prev = lines [ k ] ;
405+ const prevTrimmed = prev . trim ( ) ;
406+ if ( ! prevTrimmed || prevTrimmed . startsWith ( '#' ) ) continue ;
407+ const prevIndent = prev . match ( / ^ ( \s * ) / ) [ 1 ] . length ;
408+ if ( prevIndent < indent && prevTrimmed === 'charsets:' ) {
409+ return 'charset-item' ;
410+ }
411+ if ( prevIndent < indent ) break ;
412+ }
413+ }
414+
415+ if ( trimmed === 'options:' ) {
416+ const parentInfo = findContentParent ( lines , i , indent ) ;
417+ return parentInfo ?. format || null ;
418+ }
419+
420+ if ( indent === 0 ) break ;
421+ }
422+ return null ;
423+ }
424+
323425function makeSuggestions ( monaco , properties , range , context ) {
324426 const suggestions = [ ] ;
325427 for ( const [ key , def ] of Object . entries ( properties ) ) {
@@ -367,6 +469,8 @@ function getSortOrder(key, context) {
367469 canvas : { width : '0' , height : '1' , background : '2' , fixed : '3' } ,
368470 element : { type : '0' , content : '1' , children : '1' , src : '1' , data : '1' , direction : '2' , size : '2' , color : '2' , font : '3' , padding : '4' } ,
369471 font : { name : '0' , path : '1' , fallback : '2' } ,
472+ 'content-options' : { input_encoding : '0' , columns : '1' , font_family : '2' , char_width_ratio : '3' , charsets : '4' } ,
473+ 'content-charset-item' : { font : '0' , font_family : '1' , font_style : '2' , font_size : '3' , color : '4' , encoding : '5' , uppercase : '6' } ,
370474 } ;
371475 return priority [ context ] ?. [ key ] || '5' ;
372476}
0 commit comments