From 63a5b5a13f45524de30291d7bb149bf742ef39d0 Mon Sep 17 00:00:00 2001 From: albert-github Date: Mon, 23 Oct 2023 19:07:00 +0200 Subject: [PATCH 1/2] issue #10351 Search subpart research after a search Implemented cookie that stores the selected category --- templates/html/search.js | 43 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/templates/html/search.js b/templates/html/search.js index 6fd40c67701..5414f1907ec 100644 --- a/templates/html/search.js +++ b/templates/html/search.js @@ -22,6 +22,9 @@ @licend The above is the entire license notice for the JavaScript code in this file */ +var cookie_namespace = 'doxygen'; +var cookie_name = '_search_grp'; + function convertToId(search) { var result = ''; @@ -252,6 +255,7 @@ function SearchBox(name, resultsPath, extension) if (j==id) { node.innerHTML='•'; + writeSetting(cookie_name, id) } else { @@ -807,9 +811,45 @@ function createResults(resultsPath) } } +function writeSetting(cookie, val) +{ + if (window.chrome) { + localStorage.setItem(cookie_namespace+cookie,val); + } else { + var date = new Date(); + date.setTime(date.getTime()+(1*60*60*1000)); // default expiration is one hour + expiration = date.toGMTString(); + document.cookie = cookie_namespace + cookie + "=" + val + "; SameSite=Lax; expires=" + expiration+"; path=/"; + } +} + function init_search() { var results = document.getElementById("MSearchSelectWindow"); + + function readSetting(cookie) + { + if (window.chrome) { + var val = localStorage.getItem(cookie_namespace+cookie); + if (val) return val; + } else { + var myCookie = cookie_namespace+cookie+"="; + if (document.cookie) { + var index = document.cookie.indexOf(myCookie); + if (index != -1) { + var valStart = index + myCookie.length; + var valEnd = document.cookie.indexOf(";", valStart); + if (valEnd == -1) { + valEnd = document.cookie.length; + } + var val = document.cookie.substring(valStart, valEnd); + return val; + } + } + } + return 0; + } + results.tabIndex=0; for (var key in indexSectionLabels) { @@ -820,7 +860,6 @@ function init_search() link.innerHTML=' '+indexSectionLabels[key]; results.appendChild(link); } - searchBox.OnSelectItem(0); var input = document.getElementById("MSearchSelect"); var searchSelectWindow = document.getElementById("MSearchSelectWindow"); @@ -836,5 +875,7 @@ function init_search() } } }); + var id = readSetting(cookie_name); + searchBox.OnSelectItem(id); } /* @license-end */ From 390499d40f8cb9ea1e3440a30f33c77ead85e7db Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Sat, 28 Oct 2023 12:14:39 +0200 Subject: [PATCH 2/2] Store group name instead of index as cookie Storing the name is more robust as the list of items is dependent on the content that is parsed which may change over time. --- templates/html/search.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/templates/html/search.js b/templates/html/search.js index 5414f1907ec..3a30151d4e5 100644 --- a/templates/html/search.js +++ b/templates/html/search.js @@ -242,6 +242,25 @@ function SearchBox(name, resultsPath, extension) return count; } + this.GetSelectionIdByName = function(name) + { + var i=0,j=0; + var win=this.DOMSearchSelectWindow(); + for (i=0;i