Skip to content

Commit

Permalink
Fix the source code highlighting on source comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dns2utf8 committed Nov 15, 2019
1 parent 82cf3a4 commit 71cf364
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,38 +396,46 @@ function getSearchElement() {

document.onkeypress = handleShortcut;
document.onkeydown = handleShortcut;
document.onclick = function(ev) {
if (hasClass(ev.target, "collapse-toggle")) {
collapseDocs(ev.target, "toggle");
} else if (hasClass(ev.target.parentNode, "collapse-toggle")) {
collapseDocs(ev.target.parentNode, "toggle");
} else if (ev.target.tagName === "SPAN" && hasClass(ev.target.parentNode, "line-numbers")) {
var prev_id = 0;

var set_fragment = function(name) {
if (browserSupportsHistoryApi()) {
history.replaceState(null, null, "#" + name);
highlightSourceLines();
} else {
location.replace("#" + name);
}
};
var handleSourceHighlight = (function() {
var prev_line_id = 0;

var set_fragment = function(name) {
if (browserSupportsHistoryApi()) {
history.replaceState(null, null, "#" + name);
highlightSourceLines();
} else {
location.replace("#" + name);
}
};

var cur_id = parseInt(ev.target.id, 10);
return function(ev) {
var cur_line_id = parseInt(ev.target.id, 10);

if (ev.shiftKey && prev_id) {
if (prev_id > cur_id) {
var tmp = prev_id;
prev_id = cur_id;
cur_id = tmp;
if (ev.shiftKey && prev_line_id) {
// Swap selection if needed
if (prev_line_id > cur_line_id) {
var tmp = prev_line_id;
prev_line_id = cur_line_id;
cur_line_id = tmp;
}

set_fragment(prev_id + "-" + cur_id);
set_fragment(prev_line_id + "-" + cur_line_id);
} else {
prev_id = cur_id;
prev_line_id = cur_line_id;

set_fragment(cur_id);
set_fragment(cur_line_id);
}
}
})();

document.onclick = function(ev) {
if (hasClass(ev.target, "collapse-toggle")) {
collapseDocs(ev.target, "toggle");
} else if (hasClass(ev.target.parentNode, "collapse-toggle")) {
collapseDocs(ev.target.parentNode, "toggle");
} else if (ev.target.tagName === "SPAN" && hasClass(ev.target.parentNode, "line-numbers")) {
handleSourceHighlight(ev);
} else if (hasClass(getHelpElement(), "hidden") === false) {
var help = getHelpElement();
var is_inside_help_popup = ev.target !== help && help.contains(ev.target);
Expand Down

0 comments on commit 71cf364

Please sign in to comment.