Rollup merge of #66430 - dns2utf8:fix_code_selection_click_handler, r=GuillaumeGomez
[doc] Fix the source code highlighting on source comments The code would always forget the previous selection. r? @GuillaumeGomez
This commit is contained in:
commit
95b9766e0a
1 changed files with 39 additions and 26 deletions
|
@ -396,38 +396,51 @@ function getSearchElement() {
|
||||||
|
|
||||||
document.onkeypress = handleShortcut;
|
document.onkeypress = handleShortcut;
|
||||||
document.onkeydown = handleShortcut;
|
document.onkeydown = handleShortcut;
|
||||||
document.onclick = function(ev) {
|
|
||||||
if (hasClass(ev.target, "collapse-toggle")) {
|
var handleSourceHighlight = (function() {
|
||||||
collapseDocs(ev.target, "toggle");
|
var prev_line_id = 0;
|
||||||
} 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) {
|
var set_fragment = function(name) {
|
||||||
|
var x = window.scrollX,
|
||||||
|
y = window.scrollY;
|
||||||
if (browserSupportsHistoryApi()) {
|
if (browserSupportsHistoryApi()) {
|
||||||
history.replaceState(null, null, "#" + name);
|
history.replaceState(null, null, "#" + name);
|
||||||
highlightSourceLines();
|
highlightSourceLines();
|
||||||
} else {
|
} else {
|
||||||
location.replace("#" + name);
|
location.replace("#" + name);
|
||||||
}
|
}
|
||||||
|
// Prevent jumps when selecting one or many lines
|
||||||
|
window.scrollTo(x, y);
|
||||||
};
|
};
|
||||||
|
|
||||||
var cur_id = parseInt(ev.target.id, 10);
|
return function(ev) {
|
||||||
|
var cur_line_id = parseInt(ev.target.id, 10);
|
||||||
|
ev.preventDefault();
|
||||||
|
|
||||||
if (ev.shiftKey && prev_id) {
|
if (ev.shiftKey && prev_line_id) {
|
||||||
if (prev_id > cur_id) {
|
// Swap selection if needed
|
||||||
var tmp = prev_id;
|
if (prev_line_id > cur_line_id) {
|
||||||
prev_id = cur_id;
|
var tmp = prev_line_id;
|
||||||
cur_id = tmp;
|
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 {
|
} 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) {
|
} else if (hasClass(getHelpElement(), "hidden") === false) {
|
||||||
var help = getHelpElement();
|
var help = getHelpElement();
|
||||||
var is_inside_help_popup = ev.target !== help && help.contains(ev.target);
|
var is_inside_help_popup = ev.target !== help && help.contains(ev.target);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue