File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -504,12 +504,10 @@ export function Events(Base) {
504504 href = stripUrlExceptId ( href ) ;
505505
506506 const oldActive = dom . find ( sidebar , 'li.active' ) ;
507- const newActive = dom
508- . find (
509- sidebar ,
510- `a[href="${ href } "], a[href="${ decodeURIComponent ( /** @type {string } */ ( href ) ) } "]` ,
511- )
512- ?. closest ( 'li' ) ;
507+ const sidebarSelector = `.sidebar-nav a[href="${ href } "], .sidebar-nav a[href="${ decodeURIComponent (
508+ /** @type {string } */ ( href ) ,
509+ ) } "]`;
510+ const newActive = dom . find ( sidebar , sidebarSelector ) ?. closest ( 'li' ) ;
513511
514512 if ( newActive && newActive !== oldActive ) {
515513 oldActive ?. classList . remove ( 'active' ) ;
Original file line number Diff line number Diff line change @@ -140,6 +140,44 @@ test.describe('Search Plugin Tests', () => {
140140 } ) ;
141141 } ) ;
142142
143+ test ( 'updates the active sidebar anchor after clicking a heading result' , async ( {
144+ page,
145+ } ) => {
146+ const docsifyInitConfig = {
147+ config : {
148+ subMaxLevel : 2 ,
149+ search : {
150+ paths : [ '/' ] ,
151+ } ,
152+ } ,
153+ markdown : {
154+ homepage : `
155+ # Home
156+
157+ ## Installation
158+
159+ Searchable installation content.
160+ ` ,
161+ sidebar : '- [Home](/)' ,
162+ } ,
163+ scriptURLs : [ '/dist/plugins/search.js' ] ,
164+ } ;
165+
166+ const searchFieldElm = page . locator ( 'input[type=search]' ) ;
167+ const resultsHeadingElm = page . locator ( '.results-panel .title' ) ;
168+ const installationSidebarItem = page
169+ . locator ( '.sidebar-nav a[href="#/?id=installation"]' )
170+ . locator ( '..' ) ;
171+
172+ await docsifyInit ( docsifyInitConfig ) ;
173+
174+ await searchFieldElm . fill ( 'installation' ) ;
175+ await expect ( resultsHeadingElm ) . toHaveText ( 'Installation' ) ;
176+ await page . click ( '.matching-post a' ) ;
177+
178+ await expect ( installationSidebarItem ) . toHaveClass ( / a c t i v e / ) ;
179+ } ) ;
180+
143181 test ( 'search ignore title' , async ( { page } ) => {
144182 const docsifyInitConfig = {
145183 markdown : {
You can’t perform that action at this time.
0 commit comments