@@ -361,12 +361,13 @@ define(function (require, exports, module) {
361361 const scroll = editor . getScrollPos ( ) ;
362362 SelectionViewManager . registerSelectionViewProvider ( provider , [ "all" ] ) ;
363363 try {
364- editor . setSize ( null , 90 ) ;
365- editor . setSelection ( { line : 2 , ch : 0 } , { line : 2 , ch : 6 } ) ;
364+ // Keep both vertical gaps too small for the popup, including with smaller editor fonts.
365+ editor . setSize ( null , 70 ) ;
366+ editor . setSelection ( { line : 0 , ch : 0 } , { line : 0 , ch : 6 } ) ;
366367 editor . setScrollPos ( 0 , 0 ) ;
367- await showPopoverAtPos ( 2 , 6 ) ;
368+ await showPopoverAtPos ( 0 , 6 ) ;
368369 const popup = getBounds ( testWindow . $ ( "#selection-view-container" ) ) ;
369- expect ( popup . left ) . toBeGreaterThan ( editor . charCoords ( { line : 2 , ch : 6 } ) . left ) ;
370+ expect ( popup . left ) . toBeGreaterThan ( editor . charCoords ( { line : 0 , ch : 6 } ) . left ) ;
370371 expect ( boundsInsideWindow ( testWindow . $ ( "#selection-view-container" ) ) ) . toBe ( true ) ;
371372 } finally {
372373 SelectionViewManager . hidePreview ( ) ;
@@ -407,6 +408,9 @@ define(function (require, exports, module) {
407408 SelectionViewManager . registerSelectionViewProvider ( provider , [ "all" ] ) ;
408409 try {
409410 editor . setSelection ( { line : 0 , ch : 0 } , { line : 10 , ch : 0 } ) ;
411+ editor . setScrollPos ( 0 , 0 ) ;
412+ // Finish the programmatic selection's scroll before simulating the user's mouseup.
413+ await new Promise ( resolve => testWindow . requestAnimationFrame ( resolve ) ) ;
410414 const point = editor . charCoords ( { line : 4 , ch : 3 } ) ;
411415 const root = editor . getRootElement ( ) ;
412416 root . dispatchEvent ( new testWindow . MouseEvent ( "mouseup" , { bubbles : true , buttons : 0 ,
@@ -422,6 +426,35 @@ define(function (require, exports, module) {
422426 }
423427 } ) ;
424428
429+ it ( "ignores scroll events from the hidden selection input" , async function ( ) {
430+ SelectionViewManager . registerSelectionViewProvider ( provider , [ "all" ] ) ;
431+ try {
432+ editor . setSelection ( { line : 0 , ch : 0 } , { line : 10 , ch : 0 } ) ;
433+ await showPopoverAtPos ( 4 , 0 ) ;
434+ editor . getRootElement ( ) . querySelector ( "textarea" ) . dispatchEvent ( new testWindow . Event ( "scroll" ) ) ;
435+ expect ( SelectionViewManager . isSelectionViewShown ( ) ) . toBe ( true ) ;
436+ } finally {
437+ SelectionViewManager . hidePreview ( ) ;
438+ SelectionViewManager . removeSelectionViewProvider ( provider , [ "all" ] ) ;
439+ }
440+ } ) ;
441+
442+ it ( "dismisses when the editor viewport actually scrolls" , async function ( ) {
443+ const scroll = editor . getScrollPos ( ) ;
444+ SelectionViewManager . registerSelectionViewProvider ( provider , [ "all" ] ) ;
445+ try {
446+ editor . setSelection ( { line : 0 , ch : 0 } , { line : 10 , ch : 0 } ) ;
447+ editor . setScrollPos ( 0 , 0 ) ;
448+ await showPopoverAtPos ( 4 , 0 ) ;
449+ editor . setScrollPos ( 0 , 100 ) ;
450+ await awaitsFor ( ( ) => ! SelectionViewManager . isSelectionViewShown ( ) , "popup dismissed on scroll" ) ;
451+ } finally {
452+ SelectionViewManager . hidePreview ( ) ;
453+ SelectionViewManager . removeSelectionViewProvider ( provider , [ "all" ] ) ;
454+ editor . setScrollPos ( scroll . x , scroll . y ) ;
455+ }
456+ } ) ;
457+
425458 it ( "keeps its anchor when the mouse moves and provider content updates" , async function ( ) {
426459 SelectionViewManager . registerSelectionViewProvider ( provider , [ "all" ] ) ;
427460 try {
@@ -459,9 +492,13 @@ define(function (require, exports, module) {
459492 SelectionViewManager . registerSelectionViewProvider ( provider , [ "all" ] ) ;
460493 SelectionViewManager . hidePreview ( ) ;
461494 try {
462- if ( action !== "opens" ) { panel . show ( ) ; }
495+ if ( action !== "opens" ) {
496+ panel . show ( ) ;
497+ workspace . setPluginPanelWidth ( 250 ) ;
498+ }
463499 editor . setSelection ( { line : 7 , ch : 0 } , { line : 10 , ch : 0 } ) ;
464500 editor . setScrollPos ( 0 , 0 ) ;
501+ await new Promise ( resolve => testWindow . requestAnimationFrame ( resolve ) ) ;
465502 await showPopoverAtPos ( 7 , 0 ) ;
466503 const popup = testWindow . $ ( "#selection-view-container" ) ;
467504 const content = popup . find ( "#blinker-fluid" ) [ 0 ] ;
@@ -471,13 +508,12 @@ define(function (require, exports, module) {
471508 if ( action === "resizes" ) { workspace . setPluginPanelWidth ( 400 ) ; }
472509 if ( action === "closes" ) { panel . hide ( ) ; }
473510 expect ( SelectionViewManager . isSelectionViewShown ( ) ) . toBe ( false ) ;
474- await awaitsFor ( ( ) => {
475- const bounds = getBounds ( popup ) ;
476- const root = editor . getRootElement ( ) . getBoundingClientRect ( ) ;
477- return SelectionViewManager . isSelectionViewShown ( ) &&
478- Math . abs ( bounds . right - before ) > 30 &&
479- Math . abs ( ( bounds . right - before ) - ( root . right - beforeEditorRight ) ) < 2 ;
480- } , "popup follows the resized editor" , 3000 ) ;
511+ await awaitsFor ( ( ) => SelectionViewManager . isSelectionViewShown ( ) ,
512+ "popup restored after editor layout" , 3000 ) ;
513+ const bounds = getBounds ( popup ) ;
514+ const root = editor . getRootElement ( ) . getBoundingClientRect ( ) ;
515+ expect ( Math . abs ( bounds . right - before ) ) . toBeGreaterThan ( 30 ) ;
516+ expect ( Math . abs ( ( bounds . right - before ) - ( root . right - beforeEditorRight ) ) ) . toBeLessThan ( 2 ) ;
481517 expect ( boundsInsideWindow ( popup ) ) . toBe ( true ) ;
482518 expect ( popup . find ( "#blinker-fluid" ) [ 0 ] ) . toBe ( content ) ;
483519 } finally {
0 commit comments