From 4cfc13dca4c690330f0f53e7c699faab8146e004 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 11 Feb 2018 18:03:09 +0100 Subject: [PATCH] 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. --- css/m-dark+doxygen.compiled.css | 2 + css/m-dark.doxygen.compiled.css | 2 + css/m-doxygen.css | 2 + css/m-light+doxygen.compiled.css | 2 + css/m-light.doxygen.compiled.css | 2 + doxygen/search.js | 45 ++++++++++++++++------- doxygen/test/js-test-data/searchdata.b85 | 2 +- doxygen/test/js-test-data/searchdata.bin | Bin 650 -> 638 bytes doxygen/test/populate-js-test-data.py | 2 +- doxygen/test/test-search.js | 22 ++++++----- 10 files changed, 56 insertions(+), 25 deletions(-) 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>aA9X8{Em2_zUMF L+zRPVpS$`88FLZS diff --git a/doxygen/test/populate-js-test-data.py b/doxygen/test/populate-js-test-data.py index a7d873c0..5f2bc555 100755 --- a/doxygen/test/populate-js-test-data.py +++ b/doxygen/test/populate-js-test-data.py @@ -67,7 +67,7 @@ trie.insert("min()", index) trie.insert("subpage", map.add("Page » Subpage", "subpage.html", flags=ResultFlag.PAGE)) trie.insert("rectangle", map.add("Rectangle", "", alias=range_index)) -trie.insert("rect()", map.add("Rectangle::Rect()", "", suffix_length=2, alias=range_index)) +trie.insert("rect", map.add("Rectangle::Rect()", "", suffix_length=2, alias=range_index)) with open(basedir/'searchdata.bin', 'wb') as f: f.write(serialize_search_data(trie, map, 7)) diff --git a/doxygen/test/test-search.js b/doxygen/test/test-search.js index 3c873af8..e85daa25 100644 --- a/doxygen/test/test-search.js +++ b/doxygen/test/test-search.js @@ -70,7 +70,7 @@ const { StringDecoder } = require('string_decoder'); /* Verify that base85-decoded file is equivalent to the binary */ { let binary = fs.readFileSync(path.join(__dirname, "js-test-data/searchdata.bin")); - assert.equal(binary.byteLength, 650); + assert.equal(binary.byteLength, 638); let b85 = fs.readFileSync(path.join(__dirname, "js-test-data/searchdata.b85"), {encoding: 'utf-8'}); assert.deepEqual(new DataView(binary.buffer.slice(binary.byteOffset, binary.byteOffset + binary.byteLength)), new DataView(Search.base85decode(b85), 0, binary.byteLength)); } @@ -105,7 +105,7 @@ const { StringDecoder } = require('string_decoder'); { let buffer = fs.readFileSync(path.join(__dirname, "js-test-data/searchdata.bin")); assert.ok(Search.init(buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength))); - assert.equal(Search.dataSize, 650); + assert.equal(Search.dataSize, 638); assert.equal(Search.symbolCount, 7); assert.equal(Search.maxResults, 100); @@ -170,25 +170,27 @@ const { StringDecoder } = require('string_decoder'); /* Alias */ assert.deepEqual(Search.search('r'), [ - { name: 'Math::Range', + { name: 'Rectangle::Rect()', + alias: 'Math::Range', url: 'classMath_1_1Range.html', flags: 40, - suffixLength: 4 }, - { name: 'Rectangle::Rect(): Math::Range', + suffixLength: 5 }, + { name: 'Math::Range', url: 'classMath_1_1Range.html', flags: 40, - suffixLength: 20 }, - { name: 'Rectangle: Math::Range', + suffixLength: 4 }, + { name: 'Rectangle', + alias: 'Math::Range', url: 'classMath_1_1Range.html', flags: 40, - suffixLength: 21 }]); + suffixLength: 8 }]); } /* Search, limiting the results to 3 */ { let buffer = fs.readFileSync(path.join(__dirname, "js-test-data/searchdata.bin")); assert.ok(Search.init(buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength), 3)); - assert.equal(Search.dataSize, 650); + assert.equal(Search.dataSize, 638); assert.equal(Search.symbolCount, 7); assert.equal(Search.maxResults, 3); assert.deepEqual(Search.search('m'), [ @@ -210,7 +212,7 @@ const { StringDecoder } = require('string_decoder'); { let b85 = fs.readFileSync(path.join(__dirname, "js-test-data/searchdata.b85"), {encoding: 'utf-8'}); assert.ok(Search.load(b85)); - assert.equal(Search.dataSize, 652); /* some padding on the end, that's okay */ + assert.equal(Search.dataSize, 640); /* some padding on the end, that's okay */ assert.equal(Search.symbolCount, 7); assert.equal(Search.maxResults, 100); assert.deepEqual(Search.search('min'), [ -- 2.30.2