Verified Commit 2b5da708 authored by Camil Staps's avatar Camil Staps 🚀

Searching for "instance X" now returns class results with all information unfolded (resolves #216)

parent cd182f61
Pipeline #16327 passed with stage
in 15 minutes and 53 seconds
...@@ -16,6 +16,7 @@ var old_libs = null; ...@@ -16,6 +16,7 @@ var old_libs = null;
var old_include_builtins = -1; var old_include_builtins = -1;
var old_include_core = -1; var old_include_core = -1;
var old_include_apps = -1; var old_include_apps = -1;
var unfold_more_information = false;
// https://stackoverflow.com/a/4812022/1544337 // https://stackoverflow.com/a/4812022/1544337
Element.prototype.getCaretPosition = function() { Element.prototype.getCaretPosition = function() {
...@@ -752,6 +753,13 @@ function getResults(str, libs, include_builtins, include_core, include_apps, pag ...@@ -752,6 +753,13 @@ function getResults(str, libs, include_builtins, include_core, include_apps, pag
responsedata['suggestions'].length > 0) { responsedata['suggestions'].length > 0) {
par.insertBefore(makeSuggestions(responsedata['suggestions']), par.firstChild); par.insertBefore(makeSuggestions(responsedata['suggestions']), par.firstChild);
} }
if (unfold_more_information) {
var togglers = elem.getElementsByClassName('toggler');
for (var i=0; i<togglers.length; i++)
toggle(togglers[i], true);
unfold_more_information = false;
}
} }
}; };
...@@ -814,17 +822,7 @@ function formsubmit() { ...@@ -814,17 +822,7 @@ function formsubmit() {
return; return;
} }
} else if (q.indexOf('instance ') == 0) { } else if (q.indexOf('instance ') == 0) {
var qname = q.substr(9); unfold_more_information = true;
var sug =
[ ['class ' + qname, highlightQuery('class ' + qname)]
, ['type ' + qname, highlightQuery('type ' + qname)]
];
sresults.innerHTML += '<p>' +
'Cloogle does not accept spaces in the input. ' +
'Did you mean to search for ' +
'<a class="hidden" href="#' + sug[0][0] + '"><code>' + sug[0][1] + '</code></a> or ' +
'<a class="hidden" href="#' + sug[1][0] + '"><code>' + sug[1][1] + '</code></a>?</p>';
return;
} }
var libs = getLibs(); var libs = getLibs();
......
...@@ -195,6 +195,8 @@ if ($_SERVER['REQUEST_METHOD'] !== 'GET'){ ...@@ -195,6 +195,8 @@ if ($_SERVER['REQUEST_METHOD'] !== 'GET'){
} }
} elseif (substr($name, 0, 6) == 'class ') { } elseif (substr($name, 0, 6) == 'class ') {
$command['className'] = substr($name, 6); $command['className'] = substr($name, 6);
} elseif (substr($name, 0, 9) == 'instance ') {
$command['className'] = substr($name, 9);
} elseif (substr($name, 0, 5) == 'type ') { } elseif (substr($name, 0, 5) == 'type ') {
$command['typeName'] = substr($name, 5); $command['typeName'] = substr($name, 5);
} elseif ($name != '') { } elseif ($name != '') {
......
...@@ -91,9 +91,9 @@ function highlightCallback(span, cls, str) { ...@@ -91,9 +91,9 @@ function highlightCallback(span, cls, str) {
function highlightQuery(query) { function highlightQuery(query) {
var highlighter = highlightClean; var highlighter = highlightClean;
if (query == 'class' || query == 'type' || query == 'using') { if (query == 'class' || query == 'instance' || query == 'type' || query == 'using') {
return '<span class="keyword">' + query + '</span>'; return '<span class="keyword">' + query + '</span>';
} else if (query.match(/^class\s/)) { } else if (query.match(/^class\s/) || query.match(/^instance\s/)) {
highlighter = highlightClean; highlighter = highlightClean;
} else if (query.match(/^type\s/)) { } else if (query.match(/^type\s/)) {
highlighter = function(q) { highlighter = function(q) {
......
...@@ -107,11 +107,11 @@ ...@@ -107,11 +107,11 @@
</tr> </tr>
<tr> <tr>
<td class='code'>type Maybe</td> <td class='code'>type Maybe</td>
<td class='description'>The type definition of <code>Maybe x</code></td> <td class='description'>Types with the exact name <code>Maybe</code></td>
</tr> </tr>
<tr> <tr>
<td class='code'>class Text</td> <td class='code'>class Text</td>
<td class='description'>The class definition of <code>Text</code></td> <td class='description'>Classes with the exact name <code>Text</code></td>
</tr> </tr>
</table> </table>
<p>Besides this web app, there are <a href="https://gitlab.science.ru.nl/cloogle/cloogle-org/#frontends">other frontends</a> available.</p> <p>Besides this web app, there are <a href="https://gitlab.science.ru.nl/cloogle/cloogle-org/#frontends">other frontends</a> available.</p>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment