@@ -298,13 +298,13 @@ function addEventHandlers(acediff) {
298298function copy ( acediff , e , dir ) {
299299 const diffIndex = parseInt ( e . target . getAttribute ( 'data-diff-index' ) , 10 ) ;
300300 const diff = acediff . diffs [ diffIndex ] ;
301- let sourceEditor ,
302- targetEditor ;
301+ let sourceEditor ;
302+ let targetEditor ;
303303
304- let startLine ,
305- endLine ,
306- targetStartLine ,
307- targetEndLine ;
304+ let startLine ;
305+ let endLine ;
306+ let targetStartLine ;
307+ let targetEndLine ;
308308 if ( dir === C . LTR ) {
309309 sourceEditor = acediff . editors . left ;
310310 targetEditor = acediff . editors . right ;
@@ -322,29 +322,13 @@ function copy(acediff, e, dir) {
322322 }
323323
324324 let contentToInsert = '' ;
325- for ( var i = startLine ; i < endLine ; i ++ ) {
325+ for ( let i = startLine ; i < endLine ; i += 1 ) {
326326 contentToInsert += `${ getLine ( sourceEditor , i ) } \n` ;
327327 }
328328
329- let startContent = '' ;
330- for ( var i = 0 ; i < targetStartLine ; i ++ ) {
331- startContent += `${ getLine ( targetEditor , i ) } \n` ;
332- }
333-
334- let endContent = '' ;
335- const totalLines = targetEditor . ace . getSession ( ) . getLength ( ) ;
336- for ( var i = targetEndLine ; i < totalLines ; i ++ ) {
337- endContent += getLine ( targetEditor , i ) ;
338- if ( i < totalLines - 1 ) {
339- endContent += '\n' ;
340- }
341- }
342-
343- endContent = endContent . replace ( / \s * $ / , '' ) ;
344-
345329 // keep track of the scroll height
346330 const h = targetEditor . ace . getSession ( ) . getScrollTop ( ) ;
347- targetEditor . ace . getSession ( ) . setValue ( startContent + contentToInsert + endContent ) ;
331+ targetEditor . ace . getSession ( ) . replace ( new Range ( targetStartLine , 0 , targetEndLine , 0 ) , contentToInsert ) ;
348332 targetEditor . ace . getSession ( ) . setScrollTop ( parseInt ( h , 10 ) ) ;
349333
350334 acediff . diff ( ) ;
0 commit comments