File tree Expand file tree Collapse file tree 2 files changed +8
-5
lines changed
Expand file tree Collapse file tree 2 files changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,8 @@ export class Contract {
4242 }
4343
4444 insertLinesBefore ( lines , line ) {
45- line += this . offset ( line ) ;
45+ let currentOffset = this . offset ( line ) ;
46+ line += this . offset ( line + currentOffset ) ;
4647 this . addOffset ( line , lines . length ) ;
4748 this . lines . splice ( line , 0 , ...lines ) ;
4849 }
@@ -72,9 +73,10 @@ export class Contract {
7273 let offsetAmount = 0 ;
7374 for ( let offset in this . offsets ) {
7475 if ( this . offsets . hasOwnProperty ( offset ) ) {
75- offsetAmount += this . offsets [ offset ] ;
76+ if ( line >= offset )
77+ offsetAmount += this . offsets [ offset ] ;
78+ }
7679 }
77- }
7880 return offsetAmount ;
7981 }
8082}
Original file line number Diff line number Diff line change @@ -60,14 +60,15 @@ test('Insert text before', (t) => {
6060} ) ;
6161
6262test ( 'Insert text before with offset' , ( t ) => {
63- t . plan ( 5 ) ;
63+ t . plan ( 6 ) ;
6464 let contract = new Contract ( [ 'line1' , 'line2' ] ) ;
6565 contract . insertTextBefore ( 'test1\nbla' , 0 ) ;
6666 t . equal ( contract . getLineAt ( 0 ) , 'test1' ) ;
6767 t . equal ( contract . getLineAt ( 1 ) , 'bla' ) ;
6868 t . equal ( contract . offset ( 0 ) , 2 ) ;
6969 contract . insertTextBefore ( 'offset' , 0 ) ;
70- t . equal ( contract . offset ( 0 ) , 3 ) ;
70+ t . equal ( contract . offset ( 0 ) , 2 ) ;
71+ t . equal ( contract . offset ( 2 ) , 3 ) ;
7172 t . equal ( contract . getLineAt ( 2 ) , 'offset' ) ;
7273} ) ;
7374
You can’t perform that action at this time.
0 commit comments