@@ -76,8 +76,14 @@ export const assignemntLanguageMonarchDefinition: monaco.languages.IMonarchLangu
7676 } ,
7777} ;
7878
79+ interface ReplacementData {
80+ old : string ;
81+ replacement : string ;
82+ type : string ;
83+ }
84+
7985interface ReplaceableAbstractWord extends AbstractWord {
80- replaceWord ( text : string , old : string , replacement : string ) : string ;
86+ replaceWord ( text : string , replacement : ReplacementData ) : string ;
8187}
8288
8389type WordOrReplacableWord = ReplaceableAbstractWord | AbstractWord ;
@@ -87,9 +93,9 @@ export class ReplaceAutoCompleteTree extends AutoCompleteTree {
8793 super ( roots ) ;
8894 }
8995
90- public replace ( lines : string [ ] , old : string , replacement : string ) : string [ ] {
96+ public replace ( lines : string [ ] , replacement : ReplacementData ) : string [ ] {
9197 const tokens = this . tokenize ( lines ) ;
92- const replaced = this . replaceToken ( this . roots , tokens , 0 , old , replacement ) ;
98+ const replaced = this . replaceToken ( this . roots , tokens , 0 , replacement ) ;
9399 const newLines : string [ ] = [ ] ;
94100 let currentLine = "" ;
95101 for ( let i = 0 ; i < tokens . length ; i ++ ) {
@@ -109,8 +115,7 @@ export class ReplaceAutoCompleteTree extends AutoCompleteTree {
109115 nodes : AutoCompleteNode < WordOrReplacableWord > [ ] ,
110116 tokens : Token [ ] ,
111117 index : number ,
112- old : string ,
113- replacement : string ,
118+ replacement : ReplacementData ,
114119 skipStartCheck = false ,
115120 ) : string [ ] {
116121 if ( index >= tokens . length ) {
@@ -120,13 +125,13 @@ export class ReplaceAutoCompleteTree extends AutoCompleteTree {
120125 if ( ! skipStartCheck && tokens [ index ] . column == 1 ) {
121126 const matchesAnyRoot = this . roots . some ( ( n ) => n . word . verifyWord ( tokens [ index ] . text ) . length === 0 ) ;
122127 if ( matchesAnyRoot ) {
123- return this . replaceToken ( this . roots , tokens , index , old , replacement , true ) ;
128+ return this . replaceToken ( this . roots , tokens , index , replacement , true ) ;
124129 }
125130 }
126131 let text = tokens [ index ] . text ;
127132 for ( const n of nodes ) {
128133 if ( ( n . word as ReplaceableAbstractWord ) . replaceWord ) {
129- text = ( n . word as ReplaceableAbstractWord ) . replaceWord ( text , old , replacement ) ;
134+ text = ( n . word as ReplaceableAbstractWord ) . replaceWord ( text , replacement ) ;
130135 }
131136 }
132137 return [
@@ -135,7 +140,6 @@ export class ReplaceAutoCompleteTree extends AutoCompleteTree {
135140 nodes . flatMap ( ( n ) => n . children ) ,
136141 tokens ,
137142 index + 1 ,
138- old ,
139143 replacement ,
140144 ) ,
141145 ] ;
@@ -314,9 +318,9 @@ class LabelWord implements ReplaceableAbstractWord {
314318 return [ ] ;
315319 }
316320
317- replaceWord ( text : string , old : string , replacement : string ) {
318- if ( text == old ) {
319- return replacement ;
321+ replaceWord ( text : string , replacement : ReplacementData ) {
322+ if ( replacement . type == "Label" && text == replacement . old ) {
323+ return replacement . replacement ;
320324 }
321325 return text ;
322326 }
@@ -348,9 +352,9 @@ class LabelListWord implements ReplaceableAbstractWord {
348352 return errors ;
349353 }
350354
351- replaceWord ( text : string , old : string , replacement : string ) {
355+ replaceWord ( text : string , replacement : ReplacementData ) {
352356 const parts = text . split ( "," ) ;
353- const newParts = parts . map ( ( part ) => this . labelWord . replaceWord ( part , old , replacement ) ) ;
357+ const newParts = parts . map ( ( part ) => this . labelWord . replaceWord ( part , replacement ) ) ;
354358 return newParts . join ( "," ) ;
355359 }
356360}
@@ -372,9 +376,9 @@ class InputWord extends InputAwareWord implements ReplaceableAbstractWord {
372376 return [ `Unknown input "${ word } "` ] ;
373377 }
374378
375- replaceWord ( text : string , old : string , replacement : string ) {
376- if ( text == old ) {
377- return replacement ;
379+ replaceWord ( text : string , replacement : ReplacementData ) {
380+ if ( replacement . type == "Input" && text == replacement . old ) {
381+ return replacement . replacement ;
378382 }
379383 return text ;
380384 }
@@ -411,9 +415,9 @@ class InputListWord implements ReplaceableAbstractWord {
411415 return errors ;
412416 }
413417
414- replaceWord ( text : string , old : string , replacement : string ) {
418+ replaceWord ( text : string , replacement : ReplacementData ) {
415419 const parts = text . split ( "," ) ;
416- const newParts = parts . map ( ( part ) => this . inputWord . replaceWord ( part , old , replacement ) ) ;
420+ const newParts = parts . map ( ( part ) => this . inputWord . replaceWord ( part , replacement ) ) ;
417421 return newParts . join ( "," ) ;
418422 }
419423}
@@ -457,12 +461,12 @@ class InputLabelWord implements ReplaceableAbstractWord {
457461 return [ ...inputErrors , ...labelErrors ] ;
458462 }
459463
460- replaceWord ( text : string , old : string , replacement : string ) {
464+ replaceWord ( text : string , replacement : ReplacementData ) {
461465 const [ input , label ] = this . getParts ( text ) ;
462- if ( input === old ) {
463- return replacement + ( label ? "." + label : "" ) ;
464- } else if ( label === old ) {
465- return input + "." + replacement ;
466+ if ( replacement . type == "Input" && input === replacement . old ) {
467+ return replacement . replacement + ( label ? "." + label : "" ) ;
468+ } else if ( replacement . type == "Label" && label === replacement . old ) {
469+ return input + "." + replacement . replacement ;
466470 }
467471 return text ;
468472 }
0 commit comments