@@ -378,35 +378,50 @@ describe('TextEditorComponent', () => {
378
378
expect ( horizontalScrollbar . style . visibility ) . toBe ( '' )
379
379
} )
380
380
381
- it ( 'updates the bottom/right of dummy scrollbars and client height/width measurements without forgetting the previous scroll top/left when scrollbar styles change' , async ( ) => {
382
- const { component, element, editor} = buildComponent ( { height : 100 , width : 100 } )
383
- expect ( getHorizontalScrollbarHeight ( component ) ) . toBeGreaterThan ( 10 )
384
- expect ( getVerticalScrollbarWidth ( component ) ) . toBeGreaterThan ( 10 )
385
- setScrollTop ( component , 20 )
386
- setScrollLeft ( component , 10 )
387
- await component . getNextUpdatePromise ( )
388
-
389
- const style = document . createElement ( 'style' )
390
- style . textContent = '::-webkit-scrollbar { height: 10px; width: 10px; }'
391
- jasmine . attachToDOM ( style )
381
+ describe ( 'when scrollbar styles change or the editor element is detached and then reattached' , ( ) => {
382
+ it ( 'updates the bottom/right of dummy scrollbars and client height/width measurements' , async ( ) => {
383
+ const { component, element, editor} = buildComponent ( { height : 100 , width : 100 } )
384
+ expect ( getHorizontalScrollbarHeight ( component ) ) . toBeGreaterThan ( 10 )
385
+ expect ( getVerticalScrollbarWidth ( component ) ) . toBeGreaterThan ( 10 )
386
+ setScrollTop ( component , 20 )
387
+ setScrollLeft ( component , 10 )
388
+ await component . getNextUpdatePromise ( )
392
389
393
- TextEditor . didUpdateScrollbarStyles ( )
394
- await component . getNextUpdatePromise ( )
390
+ // Updating scrollbar styles.
391
+ const style = document . createElement ( 'style' )
392
+ style . textContent = '::-webkit-scrollbar { height: 10px; width: 10px; }'
393
+ jasmine . attachToDOM ( style )
394
+ TextEditor . didUpdateScrollbarStyles ( )
395
+ await component . getNextUpdatePromise ( )
395
396
396
- expect ( getHorizontalScrollbarHeight ( component ) ) . toBe ( 10 )
397
- expect ( getVerticalScrollbarWidth ( component ) ) . toBe ( 10 )
398
- expect ( component . refs . horizontalScrollbar . element . style . right ) . toBe ( '10px' )
399
- expect ( component . refs . verticalScrollbar . element . style . bottom ) . toBe ( '10px' )
400
- expect ( component . refs . horizontalScrollbar . element . scrollLeft ) . toBe ( 10 )
401
- expect ( component . refs . verticalScrollbar . element . scrollTop ) . toBe ( 20 )
402
- expect ( component . getScrollContainerClientHeight ( ) ) . toBe ( 100 - 10 )
403
- expect ( component . getScrollContainerClientWidth ( ) ) . toBe ( 100 - component . getGutterContainerWidth ( ) - 10 )
397
+ expect ( getHorizontalScrollbarHeight ( component ) ) . toBe ( 10 )
398
+ expect ( getVerticalScrollbarWidth ( component ) ) . toBe ( 10 )
399
+ expect ( component . refs . horizontalScrollbar . element . style . right ) . toBe ( '10px' )
400
+ expect ( component . refs . verticalScrollbar . element . style . bottom ) . toBe ( '10px' )
401
+ expect ( component . refs . horizontalScrollbar . element . scrollLeft ) . toBe ( 10 )
402
+ expect ( component . refs . verticalScrollbar . element . scrollTop ) . toBe ( 20 )
403
+ expect ( component . getScrollContainerClientHeight ( ) ) . toBe ( 100 - 10 )
404
+ expect ( component . getScrollContainerClientWidth ( ) ) . toBe ( 100 - component . getGutterContainerWidth ( ) - 10 )
405
+
406
+ // Detaching and re-attaching the editor element.
407
+ element . remove ( )
408
+ jasmine . attachToDOM ( element )
404
409
405
- // Ensure we don't throw an error trying to remeasure non-existent scrollbars for mini editors.
406
- await editor . update ( { mini : true } )
407
- TextEditor . didUpdateScrollbarStyles ( )
408
- component . scheduleUpdate ( )
409
- await component . getNextUpdatePromise ( )
410
+ expect ( getHorizontalScrollbarHeight ( component ) ) . toBe ( 10 )
411
+ expect ( getVerticalScrollbarWidth ( component ) ) . toBe ( 10 )
412
+ expect ( component . refs . horizontalScrollbar . element . style . right ) . toBe ( '10px' )
413
+ expect ( component . refs . verticalScrollbar . element . style . bottom ) . toBe ( '10px' )
414
+ expect ( component . refs . horizontalScrollbar . element . scrollLeft ) . toBe ( 10 )
415
+ expect ( component . refs . verticalScrollbar . element . scrollTop ) . toBe ( 20 )
416
+ expect ( component . getScrollContainerClientHeight ( ) ) . toBe ( 100 - 10 )
417
+ expect ( component . getScrollContainerClientWidth ( ) ) . toBe ( 100 - component . getGutterContainerWidth ( ) - 10 )
418
+
419
+ // Ensure we don't throw an error trying to remeasure non-existent scrollbars for mini editors.
420
+ await editor . update ( { mini : true } )
421
+ TextEditor . didUpdateScrollbarStyles ( )
422
+ component . scheduleUpdate ( )
423
+ await component . getNextUpdatePromise ( )
424
+ } )
410
425
} )
411
426
412
427
it ( 'renders cursors within the visible row range' , async ( ) => {
@@ -1142,7 +1157,7 @@ describe('TextEditorComponent', () => {
1142
1157
expect ( component . getScrollTopRow ( ) ) . toBe ( 4 )
1143
1158
expect ( component . getScrollTop ( ) ) . toBe ( Math . round ( 4 * component . getLineHeight ( ) ) )
1144
1159
1145
- // Preserves the scrollTopRow when sdetached
1160
+ // Preserves the scrollTopRow when detached
1146
1161
element . remove ( )
1147
1162
expect ( component . getScrollTopRow ( ) ) . toBe ( 4 )
1148
1163
expect ( component . getScrollTop ( ) ) . toBe ( Math . round ( 4 * component . getLineHeight ( ) ) )
0 commit comments