@@ -21,7 +21,7 @@ const getKeywordRanges = (
2121 const ranges : { start : number ; end : number } [ ] = [ ]
2222 // This regex is a combination of all keyword types
2323 const regex =
24- / ` ( [ ^ \s ` ] * \. [ ^ \s ` ] + ) ` | ( # C h a n g e s : [ ^ \s , ; : ! ? ] + ) | ( # S e l e c t i o n ) | ( # 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 + " [ ^ " ] + " ) | ( # (?: C o m m i t | C o n t e x t A t C o m m i t ) : [ ^ : ] + : [ ^ \s " ] + \s + " (?: \\ .| [ ^ " \\ ] ) * " ) | ( < f r a g m e n t p a t h = " [ ^ " ] + " (?: [ ^ > ] + ) ? > \n [ \s \S ] * ?\n < \/ f r a g m e n t > ) / g
24+ / ` ( [ ^ \s ` ] * \. [ ^ \s ` ] + ) ` | ( # C h a n g e s : [ ^ \s , ; : ! ? ] + ) | ( # S e l e c t i o n ) | ( # 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 + " [ ^ " ] + " ) | ( # (?: C o m m i t | C o n t e x t A t C o m m i t ) : [ ^ : ] + : [ ^ \s " ] + \s + " (?: \\ .| [ ^ " \\ ] ) * " ) | ( < f r a g m e n t p a t h = " [ ^ " ] + " (?: [ ^ > ] + ) ? > \n [ \s \S ] * ?\n < \/ f r a g m e n t > ) | ( # S k i l l : [ ^ : ] + : [ ^ : ] + : [ ^ \s ] + ) / g
2525
2626 let match
2727 while ( ( match = regex . exec ( text ) ) !== null ) {
@@ -149,6 +149,18 @@ const reconstruct_raw_value_from_node = (node: Node): string => {
149149 }
150150
151151 return `<fragment ${ attributes } >\n${ content } \n</fragment>`
152+ } else if ( el . dataset . type == 'skill-keyword' ) {
153+ const agent = el . dataset . agent
154+ const repo = el . dataset . repo
155+ const skillName = el . dataset . skillName
156+ if ( ! agent || ! repo || ! skillName ) return ''
157+
158+ const index = inner_content . indexOf ( skillName )
159+ if ( index != - 1 ) {
160+ const prefix = inner_content . substring ( 0 , index )
161+ const suffix = inner_content . substring ( index + skillName . length )
162+ return `${ prefix } #Skill:${ agent } :${ repo } :${ skillName } ${ suffix } `
163+ }
152164 }
153165
154166 return inner_content
@@ -310,6 +322,18 @@ export const use_handlers = (
310322 const search_pattern = `#ContextAtCommit:${ repo_name } :${ commit_hash } "${ commit_message . replace ( / " / g, '\\"' ) } "`
311323 const start_index = props . value . indexOf ( search_pattern )
312324
325+ if ( start_index !== - 1 ) {
326+ apply_keyword_deletion ( start_index , start_index + search_pattern . length )
327+ }
328+ } else if ( keyword_type == 'skill-keyword' ) {
329+ const agent = keyword_element . dataset . agent
330+ const repo = keyword_element . dataset . repo
331+ const skillName = keyword_element . dataset . skillName
332+ if ( ! agent || ! repo || ! skillName ) return
333+
334+ const search_pattern = `#Skill:${ agent } :${ repo } :${ skillName } `
335+ const start_index = props . value . indexOf ( search_pattern )
336+
313337 if ( start_index !== - 1 ) {
314338 apply_keyword_deletion ( start_index , start_index + search_pattern . length )
315339 }
@@ -658,6 +682,22 @@ export const use_handlers = (
658682 return false
659683 }
660684
685+ const handle_skill_keyword_deletion = ( raw_pos : number ) : boolean => {
686+ const text_before_cursor = props . value . substring ( 0 , raw_pos )
687+ const match = text_before_cursor . match ( / # S k i l l : [ ^ : ] + : [ ^ : ] + : [ ^ \s ] + $ / )
688+
689+ if ( match ) {
690+ const start_of_match = raw_pos - match [ 0 ] . length
691+ const new_value =
692+ props . value . substring ( 0 , start_of_match ) +
693+ props . value . substring ( raw_pos )
694+ const new_raw_cursor_pos = start_of_match
695+ update_value ( new_value , new_raw_cursor_pos )
696+ return true
697+ }
698+ return false
699+ }
700+
661701 const handle_pasted_lines_keyword_deletion = ( raw_pos : number ) : boolean => {
662702 const text_before_cursor = props . value . substring ( 0 , raw_pos )
663703
@@ -718,6 +758,10 @@ export const use_handlers = (
718758 return handle_commit_keyword_deletion ( raw_pos , context_file_paths )
719759 }
720760
761+ if ( el . dataset . type == 'skill-keyword' ) {
762+ return handle_skill_keyword_deletion ( raw_pos )
763+ }
764+
721765 if ( el . dataset . type == 'pasted-lines-keyword' ) {
722766 return handle_pasted_lines_keyword_deletion ( raw_pos )
723767 }
@@ -760,7 +804,8 @@ export const use_handlers = (
760804 parent . dataset . type == 'saved-context-keyword' ||
761805 parent . dataset . type == 'commit-keyword' ||
762806 parent . dataset . type == 'contextatcommit-keyword' ||
763- parent . dataset . type == 'pasted-lines-keyword'
807+ parent . dataset . type == 'pasted-lines-keyword' ||
808+ parent . dataset . type == 'skill-keyword'
764809 ) {
765810 const rangeAfter = document . createRange ( )
766811 rangeAfter . selectNodeContents ( parent )
@@ -786,7 +831,8 @@ export const use_handlers = (
786831 el . dataset . type == 'saved-context-keyword' ||
787832 el . dataset . type == 'commit-keyword' ||
788833 el . dataset . type == 'contextatcommit-keyword' ||
789- el . dataset . type == 'pasted-lines-keyword'
834+ el . dataset . type == 'pasted-lines-keyword' ||
835+ el . dataset . type == 'skill-keyword'
790836 ) {
791837 const display_pos = get_caret_position_from_div ( input_ref . current )
792838 if ( handle_keyword_deletion_by_backspace ( el , display_pos ) ) {
0 commit comments