11import cn from 'classnames'
22import styles from '../ChatInput.module.scss'
33
4- const escape_html = ( str : string ) : string =>
5- str
6- . replace ( / & / g, '&' )
7- . replace ( / < / g, '<' )
8- . replace ( / > / g, '>' )
9- . replace ( / " / g, '"' )
10- . replace ( / ' / g, ''' )
11-
124const process_text_part_for_files = (
135 text : string ,
146 context_file_paths : string [ ]
@@ -26,17 +18,17 @@ const process_text_part_for_files = (
2618 return `<span class="${ cn (
2719 styles [ 'keyword' ] ,
2820 styles [ 'keyword--file' ]
29- ) } " contentEditable="false" data-type="file-keyword" title="${ escape_html (
30- file_path
31- ) } "><span class=" ${ styles [ 'keyword__icon' ] } "></span><span class="${
21+ ) } " contentEditable="false" data-type="file-keyword" title="${ file_path } "><span class=" ${
22+ styles [ 'keyword__icon' ]
23+ } "></span><span class="${
3224 styles [ 'keyword__text' ]
33- } ">${ escape_html ( filename ) } </span></span>`
25+ } ">${ filename } </span></span>`
3426 }
3527 // If not a context file, return with backticks
36- return `\`${ escape_html ( file_path ) } \``
28+ return `\`${ file_path } \``
3729 }
3830 // part at even index is regular text
39- return escape_html ( part )
31+ return part
4032 } )
4133 . join ( '' )
4234}
@@ -63,15 +55,11 @@ export const get_highlighted_text = (params: {
6355 return `<span class="${ cn (
6456 styles [ 'keyword' ] ,
6557 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="Context: ${ escape_html ( context_name ) } "><span class="${
58+ ) } " contentEditable="false" data-type="saved-context-keyword" data-context-type="${ context_type } " data-context-name="${ context_name } " title="Context "${ context_name } ""><span class="${
7159 styles [ 'keyword__icon' ]
7260 } "></span><span class="${
7361 styles [ 'keyword__text' ]
74- } ">Context: ${ escape_html ( context_name ) } </span></span>`
62+ } ">Context " ${ context_name } " </span></span>`
7563 }
7664 return process_text_part_for_files ( part , params . context_file_paths )
7765 } )
@@ -86,24 +74,25 @@ export const get_highlighted_text = (params: {
8674
8775 return parts
8876 . map ( ( part ) => {
89- if ( part === '#Selection' ) {
77+ if ( part == '#Selection' ) {
9078 const className = cn ( styles [ 'keyword' ] , styles [ 'keyword--selection' ] , {
9179 [ styles [ 'keyword--selection-error' ] ] : ! params . has_active_selection
9280 } )
93- return `<span class="${ className } " contentEditable="false" data-type="selection-keyword" title="Selection"><span class="${ styles [ 'keyword__icon' ] } "></span><span class="${ styles [ 'keyword__text' ] } ">Selection</span></span>`
81+ const title = ! params . has_active_selection
82+ ? 'Missing text selection'
83+ : ''
84+ return `<span class="${ className } " contentEditable="false" data-type="selection-keyword" title="${ title } "><span class="${ styles [ 'keyword__icon' ] } "></span><span class="${ styles [ 'keyword__text' ] } ">Selection</span></span>`
9485 }
9586 if ( part && / ^ # C h a n g e s : [ ^ \s , ; : ! ? ] + $ / . test ( part ) ) {
9687 const branch_name = part . substring ( '#Changes:' . length )
9788 return `<span class="${ cn (
9889 styles [ 'keyword' ] ,
9990 styles [ 'keyword--changes' ]
100- ) } " contentEditable="false" data-type="changes-keyword" data-branch-name="${ escape_html (
101- branch_name
102- ) } " title="Diff with ${ escape_html ( branch_name ) } "><span class="${
91+ ) } " contentEditable="false" data-type="changes-keyword" data-branch-name="${ branch_name } "><span class="${
10392 styles [ 'keyword__icon' ]
10493 } "></span><span class="${
10594 styles [ 'keyword__text' ]
106- } ">Changes: ${ escape_html ( branch_name ) } </span></span>`
95+ } ">Diff with ${ branch_name } </span></span>`
10796 }
10897 const saved_context_match = part . match (
10998 / ^ # 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 + " ( [ ^ " ] + ) " $ /
@@ -114,15 +103,11 @@ export const get_highlighted_text = (params: {
114103 return `<span class="${ cn (
115104 styles [ 'keyword' ] ,
116105 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="Context: ${ escape_html ( context_name ) } "><span class="${
106+ ) } " contentEditable="false" data-type="saved-context-keyword" data-context-type="${ context_type } " data-context-name="${ context_name } " title="Context "${ context_name } ""><span class="${
122107 styles [ 'keyword__icon' ]
123108 } "></span><span class="${
124109 styles [ 'keyword__text' ]
125- } ">Context: ${ escape_html ( context_name ) } </span></span>`
110+ } ">Context " ${ context_name } " </span></span>`
126111 }
127112
128113 return process_text_part_for_files ( part , params . context_file_paths )
0 commit comments