@@ -42,7 +42,13 @@ const KEYWORDS = [
4242 'it_should_behave_like'
4343] ;
4444
45- const FOCUS_TAG = ', :focus' ;
45+ const DEFAULT_FOCUS_TAG = 'focus' ;
46+
47+ function getFocusTag ( ) : string {
48+ const raw = vscode . workspace . getConfiguration ( 'rspec-focus' ) . get < string > ( 'focusTag' , DEFAULT_FOCUS_TAG ) ;
49+ const sanitized = ( raw ?? '' ) . replace ( / ^ : + / , '' ) . replace ( / [ ^ a - z A - Z 0 - 9 _ ] .* $ / , '' ) || DEFAULT_FOCUS_TAG ;
50+ return `, :${ sanitized } ` ;
51+ }
4652
4753function getKeywordsRegexp ( ) : RegExp {
4854 return new RegExp ( `(?:${ KEYWORDS . join ( '|' ) } )\\s['"].+['"]\\sdo$` , 'm' ) ;
@@ -58,6 +64,7 @@ async function add() {
5864 return ;
5965 }
6066
67+ const focusTag = getFocusTag ( ) ;
6168 await editor . edit ( ( editBuilder ) => {
6269 const activePosition = editor . selection . active ;
6370 for ( let i = activePosition . line ; i >= 0 ; i -- ) {
@@ -66,13 +73,13 @@ async function add() {
6673 const matches = text . match ( getKeywordsRegexp ( ) ) || text . match ( getRSpecBlockRegexp ( ) ) ;
6774
6875 if ( matches ) {
69- if ( text . includes ( FOCUS_TAG ) ) {
76+ if ( text . includes ( focusTag ) ) {
7077 continue ;
7178 } else {
7279 const doIndex = text . lastIndexOf ( 'do' ) ;
7380 if ( doIndex !== - 1 ) {
7481 const position = new Position ( i , doIndex - 1 ) ;
75- editBuilder . insert ( position , FOCUS_TAG ) ;
82+ editBuilder . insert ( position , focusTag ) ;
7683 }
7784 break ;
7885 }
@@ -87,15 +94,16 @@ async function clear() {
8794 return ;
8895 }
8996
97+ const focusTag = getFocusTag ( ) ;
9098 await editor . edit ( ( editBuilder ) => {
9199 for ( let i = 0 ; i < editor . document . lineCount ; i ++ ) {
92100 const line = editor . document . lineAt ( i ) ;
93101 const text = line . text ;
94- const focusIndex = text . indexOf ( FOCUS_TAG ) ;
102+ const focusIndex = text . indexOf ( focusTag ) ;
95103
96104 if ( focusIndex !== - 1 ) {
97105 const start = new Position ( i , focusIndex ) ;
98- const end = new Position ( i , focusIndex + FOCUS_TAG . length ) ;
106+ const end = new Position ( i , focusIndex + focusTag . length ) ;
99107 editBuilder . delete ( new Range ( start , end ) ) ;
100108 }
101109 }
0 commit comments