File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -591,6 +591,26 @@ this.init();
591591 expect ( result . content ) . toBe ( 'function test() {\n return false;\n}\n' )
592592 }
593593 } )
594+
595+ it ( 'should strip line numbers with leading spaces' , ( ) => {
596+ const originalContent = 'function test() {\n return true;\n}\n'
597+ const diffContent = `test.ts
598+ <<<<<<< SEARCH
599+ 1 | function test() {
600+ 2 | return true;
601+ 3 | }
602+ =======
603+ 1 | function test() {
604+ 2 | return false;
605+ 3 | }
606+ >>>>>>> REPLACE`
607+
608+ const result = strategy . applyDiff ( originalContent , diffContent )
609+ expect ( result . success ) . toBe ( true )
610+ if ( result . success ) {
611+ expect ( result . content ) . toBe ( 'function test() {\n return false;\n}\n' )
612+ }
613+ } )
594614
595615 it ( 'should not strip when not all lines have numbers in either section' , ( ) => {
596616 const originalContent = 'function test() {\n return true;\n}\n'
Original file line number Diff line number Diff line change @@ -193,12 +193,12 @@ Result:
193193 // Strip line numbers from search and replace content if every line starts with a line number
194194 const hasLineNumbers = ( content : string ) => {
195195 const lines = content . split ( / \r ? \n / ) ;
196- return lines . length > 0 && lines . every ( line => / ^ \d + \s + \| (? ! \| ) / . test ( line ) ) ;
196+ return lines . length > 0 && lines . every ( line => / ^ \s * \ d+ \s + \| (? ! \| ) / . test ( line ) ) ;
197197 } ;
198198
199199 if ( hasLineNumbers ( searchContent ) && hasLineNumbers ( replaceContent ) ) {
200200 const stripLineNumbers = ( content : string ) => {
201- return content . replace ( / ^ \d + \s + \| (? ! \| ) / gm, '' ) ;
201+ return content . replace ( / ^ \s * \ d+ \s + \| (? ! \| ) / gm, '' ) ;
202202 } ;
203203
204204 searchContent = stripLineNumbers ( searchContent ) ;
You can’t perform that action at this time.
0 commit comments