@@ -106,17 +106,18 @@ it("reuses its DOM index while typing and its ranges while navigating", async ()
106106} ) ;
107107
108108it ( "reveals code matches inside horizontal and vertical scroll containers without moving the page" , async ( ) => {
109- await using screen = await render (
109+ const content = ( extra : string ) => (
110110 < div style = { { display : "flex" , width : 360 , height : 240 } } >
111111 < SearchableMarkdownPreview >
112112 < p > Start</ p >
113113 < div style = { { height : 600 } } />
114114 < pre style = { { overflow : "auto" , whiteSpace : "pre" , fontFamily : "monospace" } } >
115- needle { "x" . repeat ( 400 ) } needle
115+ needle { "x" . repeat ( 400 ) } needle{ extra }
116116 </ pre >
117117 </ SearchableMarkdownPreview >
118- </ div > ,
118+ </ div >
119119 ) ;
120+ await using screen = await render ( content ( "" ) ) ;
120121 const paragraph = screen . container . querySelector ( "p" ) ! ;
121122 await act ( ( ) => {
122123 requestMarkdownFindOpen ( paragraph ) ;
@@ -141,6 +142,20 @@ it("reveals code matches inside horizontal and vertical scroll containers withou
141142 expect ( window . scrollY ) . toBe ( pageTop ) ;
142143 await userEvent . keyboard ( "{Shift>}{Enter}{/Shift}" ) ;
143144 expect ( pre . scrollLeft ) . toBe ( 0 ) ;
145+ viewport . scrollTop = 0 ;
146+ await screen . rerender ( content ( " needle" ) ) ;
147+ await vi . waitFor ( ( ) => expect ( highlighted ( "t3-markdown-find" ) ) . toHaveLength ( 2 ) ) ;
148+ expect ( viewport . scrollTop ) . toBe ( 0 ) ;
149+ expect ( pre . scrollLeft ) . toBe ( 0 ) ;
150+ await userEvent . keyboard ( "{Enter}" ) ;
151+ expect ( viewport . scrollTop ) . toBeGreaterThan ( 0 ) ;
152+ expect ( pre . scrollLeft ) . toBeGreaterThan ( 0 ) ;
153+ await userEvent . fill ( screen . getByRole ( "searchbox" ) , "absent" ) ;
154+ await vi . waitFor ( ( ) => expect ( highlighted ( ) ) . toEqual ( [ ] ) ) ;
155+ viewport . scrollTop = 0 ;
156+ await screen . rerender ( content ( " absent" ) ) ;
157+ await vi . waitFor ( ( ) => expect ( highlighted ( ) ) . toEqual ( [ "absent" ] ) ) ;
158+ expect ( viewport . scrollTop ) . toBe ( 0 ) ;
144159} ) ;
145160
146161it ( "routes file toolbar focus to the visible preview, leaving hidden tabs and chat alone" , async ( ) => {
0 commit comments