From: Vladimír Vondruš Date: Sun, 11 Feb 2018 17:03:09 +0000 (+0100) Subject: doxygen: render the aliases in search better. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=4cfc13dca4c690330f0f53e7c699faab8146e004;p=blog.git doxygen: render the aliases in search better. In particular it's more important what's the alias than what's the name it points to. --- diff --git a/css/m-dark+doxygen.compiled.css b/css/m-dark+doxygen.compiled.css index 736bb49a..9d8436ed 100644 --- a/css/m-dark+doxygen.compiled.css +++ b/css/m-dark+doxygen.compiled.css @@ -2070,6 +2070,8 @@ a.m-dox-search-icon:focus svg, a.m-dox-search-icon:hover svg, a.m-dox-search-ico .m-dox-search ul#search-results li a > div { white-space: nowrap; overflow: hidden; +} +.m-dox-search ul#search-results li a > div:not(.m-dox-search-alias) { direction: rtl; } .m-dox-search ul#search-results li a .m-label { diff --git a/css/m-dark.doxygen.compiled.css b/css/m-dark.doxygen.compiled.css index 23b7a8e2..bed13779 100644 --- a/css/m-dark.doxygen.compiled.css +++ b/css/m-dark.doxygen.compiled.css @@ -256,6 +256,8 @@ a.m-dox-search-icon:focus svg, a.m-dox-search-icon:hover svg, a.m-dox-search-ico .m-dox-search ul#search-results li a > div { white-space: nowrap; overflow: hidden; +} +.m-dox-search ul#search-results li a > div:not(.m-dox-search-alias) { direction: rtl; } .m-dox-search ul#search-results li a .m-label { diff --git a/css/m-doxygen.css b/css/m-doxygen.css index 30f6a1fb..c2300901 100644 --- a/css/m-doxygen.css +++ b/css/m-doxygen.css @@ -271,6 +271,8 @@ a.m-dox-search-icon:focus svg, a.m-dox-search-icon:hover svg, a.m-dox-search-ico .m-dox-search ul#search-results li a > div { white-space: nowrap; overflow: hidden; +} +.m-dox-search ul#search-results li a > div:not(.m-dox-search-alias) { /* This is here in order to cut the text off at the left side. Besides this there's special patching needed for punctuation characters, see search.js for details. */ diff --git a/css/m-light+doxygen.compiled.css b/css/m-light+doxygen.compiled.css index e16d3f1f..36626c43 100644 --- a/css/m-light+doxygen.compiled.css +++ b/css/m-light+doxygen.compiled.css @@ -2006,6 +2006,8 @@ a.m-dox-search-icon:focus svg, a.m-dox-search-icon:hover svg, a.m-dox-search-ico .m-dox-search ul#search-results li a > div { white-space: nowrap; overflow: hidden; +} +.m-dox-search ul#search-results li a > div:not(.m-dox-search-alias) { direction: rtl; } .m-dox-search ul#search-results li a .m-label { diff --git a/css/m-light.doxygen.compiled.css b/css/m-light.doxygen.compiled.css index 6672701b..5b060ecd 100644 --- a/css/m-light.doxygen.compiled.css +++ b/css/m-light.doxygen.compiled.css @@ -256,6 +256,8 @@ a.m-dox-search-icon:focus svg, a.m-dox-search-icon:hover svg, a.m-dox-search-ico .m-dox-search ul#search-results li a > div { white-space: nowrap; overflow: hidden; +} +.m-dox-search ul#search-results li a > div:not(.m-dox-search-alias) { direction: rtl; } .m-dox-search ul#search-results li a .m-label { diff --git a/doxygen/search.js b/doxygen/search.js index ac58ef2c..f3eeeaa9 100644 --- a/doxygen/search.js +++ b/doxygen/search.js @@ -314,19 +314,21 @@ var Search = { that's just wrong, fix! */ if(aliasedIndex != null && maxUrlPrefix == 0xffffff) { let alias = this.gatherResult(aliasedIndex, 0 /* ignored */, 0xffffff); /* should be enough haha */ - name += ': ' + alias.name; url = alias.url; flags = alias.flags; - /* Result suffix length: add the whole aliased name + the `: ` */ - resultSuffixLength += 2 + alias.name.length; + /* Keeping in UTF-8, as we need that for proper slicing (and concatenating) */ + return {name: name, + alias: alias.name, + url: alias.url, + flags: alias.flags, + suffixLength: suffixLength + resultSuffixLength}; + } /* Otherwise extract URL from here */ - } else { - let max = Math.min(j + maxUrlPrefix - url.length, nextResultOffset); - for(; j != max; ++j) { - url += String.fromCharCode(this.map.getUint8(j)); - } + let max = Math.min(j + maxUrlPrefix - url.length, nextResultOffset); + for(; j != max; ++j) { + url += String.fromCharCode(this.map.getUint8(j)); } /* Keeping in UTF-8, as we need that for proper slicing (and concatenating) */ @@ -336,6 +338,11 @@ var Search = { suffixLength: suffixLength + resultSuffixLength}; }, + escape: function(name) { + return name.replace(/[\"&<>]/g, function (a) { + return { '"': '"', '&': '&', '<': '<', '>': '>' }[a]; + }); + }, escapeForRtl: function(name) { /* Besides the obvious escaping of HTML entities we also need to escape punctuation, because due to the RTL hack to cut @@ -344,9 +351,7 @@ var Search = { characters, parentheses we need to *soak* in it. But only the right ones. And that for some reason needs to be also for &. Huh. https://en.wikipedia.org/wiki/Right-to-left_mark */ - return name.replace(/[\"&<>]/g, function (a) { - return { '"': '"', '&': '&', '<': '<', '>': '>' }[a]; - }).replace(/[:=]/g, '‎$&').replace(/(\)|>|&|\/)/g, '‎$&‎'); + return this.escape(name).replace(/[:=]/g, '‎$&').replace(/(\)|>|&|\/)/g, '‎$&‎'); }, renderResults: /* istanbul ignore next */ function(value, results) { @@ -430,9 +435,23 @@ var Search = { break; } - list += this.fromUtf8('
' + type + '
' + (results[i].flags & 2 ? '
deprecated
' : '') + (results[i].flags & 4 ? '
deleted
' : '') + '
' + this.escapeForRtl(results[i].name.substr(0, results[i].name.length - value.length - results[i].suffixLength)) + '' + this.escapeForRtl(results[i].name.substr(results[i].name.length - value.length - results[i].suffixLength, value.length)) + '' + this.escapeForRtl(results[i].name.substr(results[i].name.length - results[i].suffixLength)) + '
'); + /* Labels + */ + list += '
' + type + '
' + (results[i].flags & 2 ? '
deprecated
' : '') + (results[i].flags & 4 ? '
deleted
' : ''); + + /* Render the alias (cut off from the right) */ + if(results[i].alias) { + list += '
' + this.escape(results[i].name.substr(0, results[i].name.length - value.length - results[i].suffixLength)) + '' + this.escape(results[i].name.substr(results[i].name.length - value.length - results[i].suffixLength, value.length)) + '' + this.escapeForRtl(results[i].name.substr(results[i].name.length - results[i].suffixLength)) + ': ' + this.escape(results[i].alias) + ''; + + /* Render the normal thing (cut off from the left, have to + escape for RTL) */ + } else { + list += '
' + this.escapeForRtl(results[i].name.substr(0, results[i].name.length - value.length - results[i].suffixLength)) + '' + this.escapeForRtl(results[i].name.substr(results[i].name.length - value.length - results[i].suffixLength, value.length)) + '' + this.escapeForRtl(results[i].name.substr(results[i].name.length - results[i].suffixLength)); + } + + /* The closing */ + list += '
'; } - document.getElementById('search-results').innerHTML = list; + document.getElementById('search-results').innerHTML = this.fromUtf8(list); document.getElementById('search-current').scrollIntoView(true); } else { diff --git a/doxygen/test/js-test-data/searchdata.b85 b/doxygen/test/js-test-data/searchdata.b85 index ab4e029f..fb582afa 100644 --- a/doxygen/test/js-test-data/searchdata.b85 +++ b/doxygen/test/js-test-data/searchdata.b85 @@ -1 +1 @@ -O+!-v2LOx#003|S000310RR921ONaj009U904M+f4gdgd009&L0BHdL0{{R4AOHX<00ATb04M+fDgXd(00A%n0BHaLHUI!^00BGz06GBy0suk)fI0vHNB{tG00B?{0B-;RRsaBW00CS80Am0FVgLYT0RRO600C|Q04V?gasU7*00DRa0B!&QegFVz00D#m0BryPiU0sQ0RaR6kN|)>00EW&0A&CHo&W%600E=`0B!&QssI3C00SBT0BvXh0Cund0CE5Uwg3P+0RaF2!~lRg00GJX0B8UK(f|N-0{{U40{{g800G_r04V?g<^TXF00Ha(0B!&R*Z=@w@&Ev70RRU8009C40A&CH1_1zU009gE0A~OJ5&-~i0RRX900ABW04V?h7y$rbA^`v>00Afg0CWHWG64W%00OE20AV-*0A&FH1^@s7NC5z400B$^0A~OJQUL&A00CG50B`^SUI74N00CqH0CfNa_y7QHXaE3qJ^=u7Y5@RqC;$KuKL7w}R{#JidjJ4wkpKWFvj6~X$p8SraA9X<0CRO>aA9X00EW&0A&CHo&W%600E=`0B!&QssI3C00SBT0BvXh0Cund0CE5Uwg3P+0RaF2!~lRg00GJX0B8UK(f|N-0{{U40{{g800G_r04V?g<^TXF00Ha(0B!&R*Z=@w@&Ev70RRU8009C40A&CH1_1zU009gE0A~OJ5&-~i0RadA7y$rb00ABW0CWHWCIJ9r00OE20AVZv0A&FH1^@s7JOKb@00BS&0A~OJMgag}00B$^0B`^SQUL&B00CG50CfNa_y7QHXaE3qG64W`UI74eC;$KuKL7w}R{#JidjJ4wkpKWFvj6~X$p8SraA9X<0CRO>aA9X