@@ -299,36 +299,41 @@ describe("selection action gestures", () => {
299299 expect ( surface . onSelection ) . toHaveBeenCalledOnce ( ) ;
300300 } ) ;
301301
302- it ( "re-reads the selection once scrolling settles when restoring after scroll " , ( ) => {
302+ it ( "restores after scrolling settles with a fresh anchor, without interrupting a held drag " , ( ) => {
303303 const surface = createSelectionSurface ( { restoreAfterScroll : true } ) ;
304304 surface . down ( ) ;
305+ surface . element . dispatchEvent ( event ( "scroll" ) ) ;
306+ surface . change ( ) ;
307+ surface . flush ( 1000 ) ;
308+ expect ( surface . onSelection ) . not . toHaveBeenCalled ( ) ;
305309 surface . up ( { x : 420 , y : 310 } ) ;
306310 surface . flush ( ) ;
311+ expect ( surface . onSelection . mock . calls ) . toEqual ( [ [ { x : 420 , y : 310 } ] ] ) ;
312+
307313 surface . onDismiss . mockClear ( ) ;
308314 surface . element . dispatchEvent ( event ( "scroll" ) ) ;
315+ expect ( surface . onDismiss ) . toHaveBeenCalledWith ( "cancel" ) ;
309316 surface . flush ( 100 ) ;
310317 surface . element . dispatchEvent ( event ( "scroll" ) ) ;
318+ surface . change ( ) ;
311319 surface . flush ( 100 ) ;
312- expect ( surface . onDismiss ) . toHaveBeenCalledWith ( "cancel" ) ;
313320 expect ( surface . onSelection ) . toHaveBeenCalledOnce ( ) ;
314321 surface . flush ( 50 ) ;
315- expect ( surface . onSelection ) . toHaveBeenLastCalledWith ( null ) ;
322+ expect ( surface . onSelection . mock . calls ) . toEqual ( [ [ { x : 420 , y : 310 } ] , [ null ] ] ) ;
323+ surface . flush ( 1000 ) ;
316324 expect ( surface . onSelection ) . toHaveBeenCalledTimes ( 2 ) ;
317- } ) ;
318325
319- it ( "keeps an Escape dismissal through a later scroll when restoring after scroll" , ( ) => {
320- const surface = createSelectionSurface ( { restoreAfterScroll : true } ) ;
321326 surface . down ( ) ;
322327 surface . up ( ) ;
323- surface . flush ( ) ;
324- surface . key ( "Escape" ) ;
328+ vi . advanceTimersByTime ( 0 ) ;
325329 surface . element . dispatchEvent ( event ( "scroll" ) ) ;
326- surface . change ( ) ;
327- surface . flush ( 1000 ) ;
328- expect ( surface . onSelection ) . toHaveBeenCalledOnce ( ) ;
330+ surface . flush ( 149 ) ;
331+ expect ( surface . onSelection ) . toHaveBeenCalledTimes ( 2 ) ;
332+ surface . flush ( 1 ) ;
333+ expect ( surface . onSelection . mock . calls ) . toEqual ( [ [ { x : 420 , y : 310 } ] , [ null ] , [ null ] ] ) ;
329334 } ) ;
330335
331- it ( "keeps an Escape during a settling scroll dismissed when restoring after scroll " , ( ) => {
336+ it ( "keeps Escape during scroll settling dismissed through later scrolling " , ( ) => {
332337 const surface = createSelectionSurface ( { restoreAfterScroll : true } ) ;
333338 surface . down ( ) ;
334339 surface . up ( ) ;
@@ -338,17 +343,23 @@ describe("selection action gestures", () => {
338343 surface . change ( ) ;
339344 surface . flush ( 1000 ) ;
340345 expect ( surface . onSelection ) . toHaveBeenCalledOnce ( ) ;
341- } ) ;
342346
343- it ( "teardown cancels a pending scroll restore" , ( ) => {
344- const surface = createSelectionSurface ( { restoreAfterScroll : true } ) ;
345- surface . down ( ) ;
346- surface . up ( ) ;
347- surface . flush ( ) ;
347+ surface . key ( "PageDown" ) ;
348348 surface . element . dispatchEvent ( event ( "scroll" ) ) ;
349- surface . actions . dispose ( ) ;
349+ surface . change ( ) ;
350350 surface . flush ( 1000 ) ;
351351 expect ( surface . onSelection ) . toHaveBeenCalledOnce ( ) ;
352+
353+ surface . document . dispatchEvent ( event ( "keydown" , { key : "ArrowRight" , shiftKey : true } ) ) ;
354+ surface . change ( ) ;
355+ surface . element . dispatchEvent ( event ( "scroll" ) ) ;
356+ surface . flush ( 150 ) ;
357+ expect ( surface . onSelection . mock . calls ) . toEqual ( [ [ { x : 300 , y : 200 } ] , [ null ] ] ) ;
358+ surface . key ( "Escape" ) ;
359+ surface . down ( ) ;
360+ surface . up ( ) ;
361+ surface . flush ( ) ;
362+ expect ( surface . onSelection ) . toHaveBeenCalledTimes ( 3 ) ;
352363 } ) ;
353364
354365 it ( "cancels a queued animation frame when a new press supersedes the release" , ( ) => {
@@ -455,25 +466,16 @@ describe("selection visibility", () => {
455466 const timeline = rect ( 0 , 0 , 800 , 600 ) ;
456467 const codeBlock = rect ( 100 , 200 , 400 , 260 ) ;
457468
458- it ( "shows a selection inside every clipping box " , ( ) => {
469+ it ( "only shows text overlapping both the timeline and its nested scroller " , ( ) => {
459470 expect ( isSelectionRectVisible ( rect ( 150 , 210 , 220 , 226 ) , [ timeline , codeBlock ] ) ) . toBe ( true ) ;
460- } ) ;
461-
462- it . each ( [
463- [ "scrolled left out of a code block" , rect ( 40 , 210 , 90 , 226 ) ] ,
464- [ "scrolled right out of a code block" , rect ( 420 , 210 , 480 , 226 ) ] ,
465- [ "touching the code block's edge" , rect ( 60 , 210 , 100 , 226 ) ] ,
466- ] ) ( "hides a selection %s" , ( _ , selection ) => {
467- expect ( isSelectionRectVisible ( selection , [ timeline , codeBlock ] ) ) . toBe ( false ) ;
468- } ) ;
469-
470- it ( "hides a selection above the timeline or with no width" , ( ) => {
471- expect ( isSelectionRectVisible ( rect ( 150 , - 40 , 220 , - 24 ) , [ timeline ] ) ) . toBe ( false ) ;
472- expect ( isSelectionRectVisible ( rect ( 150 , 210 , 150 , 226 ) , [ timeline ] ) ) . toBe ( false ) ;
473- } ) ;
474-
475- it ( "shows a selection that is only partly clipped" , ( ) => {
471+ expect ( isSelectionRectVisible ( rect ( 420 , 210 , 480 , 226 ) , [ timeline , codeBlock ] ) ) . toBe ( false ) ;
476472 expect ( isSelectionRectVisible ( rect ( 380 , 210 , 460 , 226 ) , [ timeline , codeBlock ] ) ) . toBe ( true ) ;
473+ expect (
474+ isSelectionRectVisible ( rect ( 150 , - 40 , 220 , - 24 ) , [ timeline , rect ( 100 , - 50 , 400 , 260 ) ] ) ,
475+ ) . toBe ( false ) ;
476+ expect (
477+ isSelectionRectVisible ( rect ( - 200 , 210 , 220 , 226 ) , [ timeline , rect ( - 200 , 200 , - 20 , 260 ) ] ) ,
478+ ) . toBe ( false ) ;
477479 } ) ;
478480} ) ;
479481
0 commit comments