@@ -10,6 +10,9 @@ var {DiffProvider} = require("./providers/default");
1010var ace = require ( "../../ace" ) ;
1111var Range = require ( "../../range" ) . Range ;
1212var editorA , editorB , diffView ;
13+ const { Decorator} = require ( "../../layer/decorators" ) ;
14+ const { ScrollDiffDecorator} = require ( "./scroll_diff_decorator" ) ;
15+
1316
1417var DEBUG = false ;
1518
@@ -28,14 +31,14 @@ function setEditorPosition(editor) {
2831
2932function getValueA ( lines ) {
3033 return lines . map ( function ( v ) {
31- return v [ 0 ] ;
34+ return v [ 0 ] ;
3235 } ) . filter ( function ( x ) {
3336 return x != null ;
3437 } ) . join ( "\n" ) ;
3538}
3639function getValueB ( lines ) {
3740 return lines . map ( function ( v ) {
38- return v . length == 2 ? v [ 1 ] : v [ 0 ] ;
41+ return v . length == 2 ? v [ 1 ] : v [ 0 ] ;
3942 } ) . filter ( function ( x ) {
4043 return x != null ;
4144 } ) . join ( "\n" ) ;
@@ -191,7 +194,7 @@ module.exports = {
191194
192195 diffView . setTheme ( "ace/theme/cloud_editor" ) ;
193196 assert . equal ( diffView . editorA . getTheme ( ) , "ace/theme/cloud_editor" ) ;
194- assert . equal ( diffView . editorB . getTheme ( ) , "ace/theme/cloud_editor" ) ;
197+ assert . equal ( diffView . editorB . getTheme ( ) , "ace/theme/cloud_editor" ) ;
195198
196199 diffView . editorB . setTheme ( "ace/theme/textmate" ) ;
197200 assert . equal ( diffView . editorA . getTheme ( ) , "ace/theme/textmate" ) ;
@@ -212,7 +215,7 @@ module.exports = {
212215
213216 diffView . detach ( ) ;
214217 checkEventRegistry ( ) ;
215-
218+
216219 } ,
217220 "test: diff at ends" : function ( ) {
218221 var diffProvider = new DiffProvider ( ) ;
@@ -353,6 +356,7 @@ module.exports = {
353356
354357 editorA . session . setValue ( getValueA ( simpleDiff ) ) ;
355358 editorB . session . setValue ( getValueB ( simpleDiff ) ) ;
359+ editorA . setOption ( "customScrollbar" , true ) ;
356360
357361 diffView = new InlineDiffView ( {
358362 editorA, editorB,
@@ -378,6 +382,8 @@ module.exports = {
378382
379383 assert . ok ( ! ! diffView . editorB . renderer . $gutterLayer . $renderer ) ;
380384
385+ assert . ok ( editorA . renderer . $scrollDecorator instanceof ScrollDiffDecorator ) ;
386+
381387 diffView . detach ( ) ;
382388
383389 assert . equal ( editorA . getOption ( "wrap" ) , "free" ) ;
@@ -388,9 +394,75 @@ module.exports = {
388394 assert . equal ( editorB . getOption ( "fadeFoldWidgets" ) , false ) ;
389395 assert . equal ( editorB . getOption ( "showFoldWidgets" ) , true ) ;
390396 assert . ok ( ! editorB . renderer . $gutterLayer . $renderer ) ;
397+
398+ assert . ok ( editorA . renderer . $scrollDecorator instanceof Decorator ) ;
391399 } ,
400+ "test split diff scroll decorators" : function ( done ) {
401+ editorA . session . setValue ( [ "a" , "b" , "c" ] . join ( "\n" ) ) ;
402+ editorB . session . setValue ( [ "a" , "c" , "X" ] . join ( "\n" ) ) ;
403+
404+ diffView = new DiffView ( { editorA, editorB } ) ;
405+ diffView . setProvider ( new DiffProvider ( ) ) ;
406+ diffView . onInput ( ) ;
407+
408+
409+ editorA . renderer . $loop . _flush ( ) ;
410+ editorB . renderer . $loop . _flush ( ) ;
411+
412+ setTimeout ( ( ) => {
413+ assertDecoratorsPlacement ( editorA , false ) ;
414+ done ( ) ;
415+ } , 0 ) ;
416+ } ,
417+ "test inline diff scroll decorators" : function ( done ) {
418+ editorA . session . setValue ( [ "a" , "b" , "c" ] . join ( "\n" ) ) ;
419+ editorB . session . setValue ( [ "a" , "c" , "X" ] . join ( "\n" ) ) ;
420+
421+ diffView = new InlineDiffView ( { editorA, editorB, showSideA : true } ) ;
422+ diffView . setProvider ( new DiffProvider ( ) ) ;
423+ diffView . onInput ( ) ;
424+
425+ editorA . renderer . $loop . _flush ( ) ;
426+
427+ setTimeout ( ( ) => {
428+ assertDecoratorsPlacement ( editorA , true ) ;
429+ done ( ) ;
430+ } , 0 ) ;
431+ }
392432} ;
393433
434+ function findPointFillStyle ( imageData , y ) {
435+ const data = imageData . slice ( 4 * y , 4 * ( y + 1 ) ) ;
436+ const a = Math . round ( data [ 3 ] / 256 * 100 ) ;
437+ if ( a === 100 ) return "rgb(" + data . slice ( 0 , 3 ) . join ( "," ) + ")" ;
438+ return "rgba(" + data . slice ( 0 , 3 ) . join ( "," ) + "," + ( a / 100 ) + ")" ;
439+ }
440+
441+ function assertDecoratorsPlacement ( editor , inlineDiff ) {
442+ const decoA = editor . renderer . $scrollDecorator ;
443+ const ctxA = decoA . canvas . getContext ( "2d" ) ;
444+ const delRow = 1 ;
445+ const offA = decoA . sessionA . documentToScreenRow ( delRow , 0 ) * decoA . lineHeight ;
446+ const centerA = offA + decoA . lineHeight / 2 ;
447+ const yA = Math . round ( decoA . heightRatio * centerA ) ;
448+ let imgA = ctxA . getImageData ( decoA . oneZoneWidth , 0 , 1 , decoA . canvasHeight ) . data ;
449+ assert . equal ( findPointFillStyle ( imgA , yA ) , decoA . colors . light . delete ) ;
450+
451+ if ( inlineDiff ) {
452+ //make sure that in inline diff, markers fills the whole line (except error decorators part)
453+ imgA = ctxA . getImageData ( decoA . canvasWidth - 1 , 0 , 1 , decoA . canvasHeight ) . data ;
454+ assert . equal ( findPointFillStyle ( imgA , yA ) , decoA . colors . light . delete ) ;
455+ }
456+
457+ const xB = decoA . oneZoneWidth * 2 ;
458+ const imgB = ctxA . getImageData ( xB , 0 , 1 , decoA . canvasHeight ) . data ;
459+
460+ const insRow = 2 ;
461+ const offB = decoA . sessionB . documentToScreenRow ( insRow , 0 ) * decoA . lineHeight ;
462+ const centerB = offB + decoA . lineHeight / 2 ;
463+ const yB = Math . round ( decoA . heightRatio * centerB ) ;
464+ assert . equal ( findPointFillStyle ( imgB , yB ) , decoA . colors . light . insert ) ;
465+ }
394466
395467if ( typeof module !== "undefined" && module === require . main ) {
396468 require ( "asyncjs" ) . test . testcase ( module . exports ) . exec ( ) ;
0 commit comments