@@ -47,28 +47,41 @@ export const get_highlighted_text = (params: {
4747 has_active_selection : boolean
4848 context_file_paths : string [ ]
4949} ) : string => {
50+ const saved_context_regex_part =
51+ '#SavedContext:(?:WorkspaceState|JSON)\\s+"[^"]+"'
5052 if ( params . is_in_code_completions_mode ) {
51- const regex = / ( # S a v e d C o n t e x t : (?: W o r k s p a c e S t a t e | J S O N ) \s + " [ ^ " ] + " ) / g
53+ const regex = new RegExp ( `( ${ saved_context_regex_part } )` , 'g' )
5254 const parts = params . text . split ( regex )
5355 return parts
5456 . map ( ( part ) => {
55- if (
56- part &&
57- / ^ # S a v e d C o n t e x t : (?: W o r k s p a c e S t a t e | J S O N ) \s + " [ ^ " ] + " $ / . test ( part )
58- ) {
59- return `<span class="${
60- styles [ 'selection-keyword' ]
61- } " contentEditable="false" data-type="selection-keyword">${ escape_html (
62- part
63- ) } </span>`
57+ const saved_context_match = part . match (
58+ / ^ # S a v e d C o n t e x t : ( W o r k s p a c e S t a t e | J S O N ) \s + " ( [ ^ " ] + ) " $ /
59+ )
60+ if ( part && saved_context_match ) {
61+ const context_type = saved_context_match [ 1 ]
62+ const context_name = saved_context_match [ 2 ]
63+ return `<span class="${ cn (
64+ styles [ 'keyword' ] ,
65+ styles [ 'keyword--saved-context' ]
66+ ) } " contentEditable="false" data-type="saved-context-keyword" data-context-type="${ escape_html (
67+ context_type
68+ ) } " data-context-name="${ escape_html (
69+ context_name
70+ ) } " title="Saved Context: ${ escape_html (
71+ context_name
72+ ) } "><span class="${ styles [ 'keyword__icon' ] } "></span><span class="${
73+ styles [ 'keyword__text' ]
74+ } ">Saved context ${ escape_html ( context_name ) } </span></span>`
6475 }
6576 return process_text_part_for_files ( part , params . context_file_paths )
6677 } )
6778 . join ( '' )
6879 }
6980
70- const regex =
71- / ( # S e l e c t i o n | # C h a n g e s : [ ^ \s , ; : ! ? ] + | # S a v e d C o n t e x t : (?: W o r k s p a c e S t a t e | J S O N ) \s + " [ ^ " ] + " ) / g
81+ const regex = new RegExp (
82+ `(#Selection|#Changes:[^\\s,;:!?]+|${ saved_context_regex_part } )` ,
83+ 'g'
84+ )
7285 const parts = params . text . split ( regex )
7386
7487 return parts
@@ -92,15 +105,24 @@ export const get_highlighted_text = (params: {
92105 styles [ 'keyword__text' ]
93106 } ">Changes</span></span>`
94107 }
95- if (
96- part &&
97- / ^ # S a v e d C o n t e x t : (?: W o r k s p a c e S t a t e | J S O N ) \s + " [ ^ " ] + " $ / . test ( part )
98- ) {
99- return `<span class="${
100- styles [ 'selection-keyword' ]
101- } " contentEditable="false" data-type="selection-keyword">${ escape_html (
102- part
103- ) } </span>`
108+ const saved_context_match = part . match (
109+ / ^ # S a v e d C o n t e x t : ( W o r k s p a c e S t a t e | J S O N ) \s + " ( [ ^ " ] + ) " $ /
110+ )
111+ if ( part && saved_context_match ) {
112+ const context_type = saved_context_match [ 1 ]
113+ const context_name = saved_context_match [ 2 ]
114+ return `<span class="${ cn (
115+ styles [ 'keyword' ] ,
116+ styles [ 'keyword--saved-context' ]
117+ ) } " contentEditable="false" data-type="saved-context-keyword" data-context-type="${ escape_html (
118+ context_type
119+ ) } " data-context-name="${ escape_html (
120+ context_name
121+ ) } " title="Saved Context: ${ escape_html ( context_name ) } "><span class="${
122+ styles [ 'keyword__icon' ]
123+ } "></span><span class="${
124+ styles [ 'keyword__text' ]
125+ } ">Saved context ${ escape_html ( context_name ) } </span></span>`
104126 }
105127
106128 return process_text_part_for_files ( part , params . context_file_paths )
0 commit comments