@@ -18,8 +18,8 @@ window["quarto-listing-loaded"] = () => {
1818
1919 if ( hash ) {
2020 // If there are categories, switch to those
21- if ( hash . categories ) {
22- const cats = hash . categories . split ( "," ) ;
21+ if ( hash . category ) {
22+ const cats = hash . category . split ( "," ) ;
2323 for ( const cat of cats ) {
2424 if ( cat ) selectedCategories . add ( decodeURIComponent ( cat ) ) ;
2525 }
@@ -87,6 +87,12 @@ window.document.addEventListener("DOMContentLoaded", function (_event) {
8787 if ( ! e . ctrlKey && ! e . metaKey ) {
8888 selectedCategories . clear ( ) ;
8989 }
90+
91+ // If this would deselect the last category, ensure default category remains selected
92+ if ( selectedCategories . has ( category ) && selectedCategories . size === 1 ) {
93+ selectedCategories . add ( kDefaultCategory ) ;
94+ }
95+
9096 activateCategory ( category ) ;
9197 setCategoryHash ( ) ;
9298 } ;
@@ -108,8 +114,8 @@ window.document.addEventListener("DOMContentLoaded", function (_event) {
108114
109115 // Process any existing hash for multiple categories
110116 const hash = getHash ( ) ;
111- if ( hash && hash . categories ) {
112- const cats = hash . categories . split ( "," ) ;
117+ if ( hash && hash . category ) {
118+ const cats = hash . category . split ( "," ) ;
113119 for ( const cat of cats ) {
114120 if ( cat ) selectedCategories . add ( decodeURIComponent ( cat ) ) ;
115121 }
@@ -261,11 +267,11 @@ function activateCategory(category) {
261267
262268function updateCategoryUI ( ) {
263269 // Deactivate all categories first
264- const activeEls = window . document . querySelectorAll (
270+ const categoryEls = window . document . querySelectorAll (
265271 ".quarto-listing-category .category"
266272 ) ;
267- for ( const activeEls of activeEls ) {
268- activeEls . classList . remove ( "active" ) ;
273+ for ( const categoryEl of categoryEls ) {
274+ categoryEl . classList . remove ( "active" ) ;
269275 }
270276
271277 // Activate selected categories
@@ -293,7 +299,7 @@ function filterListingCategory() {
293299 } else {
294300 // Filter to selected categories, but ignore kDefaultCategory if other categories selected
295301 const effectiveCategories = new Set ( selectedCategories ) ;
296- if ( effectiveCategories . size > 1 ) {
302+ if ( effectiveCategories . size > 1 && effectiveCategories . has ( kDefaultCategory ) ) {
297303 effectiveCategories . delete ( kDefaultCategory ) ;
298304 }
299305
0 commit comments