From bbd0d3e4f73cf48a2062cacc4f7da3c25641c408 Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Mon, 13 Nov 2023 11:26:29 +0100 Subject: [PATCH] fix exception when stepping backwards through code highlights #3524 --- plugin/highlight/highlight.esm.js | 2 +- plugin/highlight/highlight.js | 2 +- plugin/highlight/plugin.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin/highlight/highlight.esm.js b/plugin/highlight/highlight.esm.js index d146177c7aa..adda9ee83cf 100644 --- a/plugin/highlight/highlight.esm.js +++ b/plugin/highlight/highlight.esm.js @@ -2,4 +2,4 @@ function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"de /*! * reveal.js plugin that adds syntax highlight support. */ -const Rs={id:"highlight",HIGHLIGHT_STEP_DELIMITER:"|",HIGHLIGHT_LINE_DELIMITER:",",HIGHLIGHT_LINE_RANGE_DELIMITER:"-",hljs:fs,init:function(e){let t=e.getConfig().highlight||{};t.highlightOnLoad="boolean"!=typeof t.highlightOnLoad||t.highlightOnLoad,t.escapeHTML="boolean"!=typeof t.escapeHTML||t.escapeHTML,Array.from(e.getRevealElement().querySelectorAll("pre code")).forEach((e=>{e.parentNode.classList.add("code-wrapper");let a=e.querySelector('script[type="text/template"]');a&&(e.textContent=a.innerHTML),e.hasAttribute("data-trim")&&"function"==typeof e.innerHTML.trim&&(e.innerHTML=function(e){function t(e){return e.replace(/^[\s\uFEFF\xA0]+/g,"")}function a(e){for(var t=e.split("\n"),a=0;a=0&&""===t[a].trim();a--)t.splice(a,1);return t.join("\n")}return function(e){var n=a(e.innerHTML).split("\n"),i=n.reduce((function(e,a){return a.length>0&&t(a).length>0&&e>a.length-t(a).length?a.length-t(a).length:e}),Number.POSITIVE_INFINITY);return n.map((function(e,t){return e.slice(i)})).join("\n")}(e)}(e)),t.escapeHTML&&!e.hasAttribute("data-noescape")&&(e.innerHTML=e.innerHTML.replace(//g,">")),e.addEventListener("focusout",(function(e){fs.highlightElement(e.currentTarget)}),!1)})),"function"==typeof t.beforeHighlight&&t.beforeHighlight(fs),t.highlightOnLoad&&Array.from(e.getRevealElement().querySelectorAll("pre code")).forEach((e=>{Rs.highlightBlock(e)})),e.on("pdf-ready",(function(){[].slice.call(e.getRevealElement().querySelectorAll("pre code[data-line-numbers].current-fragment")).forEach((function(e){Rs.scrollHighlightedLineIntoView(e,{},!0)}))}))},highlightBlock:function(e){if(fs.highlightElement(e),0!==e.innerHTML.trim().length&&e.hasAttribute("data-line-numbers")){fs.lineNumbersBlock(e,{singleLine:!0});var t={currentBlock:e},a=Rs.deserializeHighlightSteps(e.getAttribute("data-line-numbers"));if(a.length>1){var n=parseInt(e.getAttribute("data-fragment-index"),10);("number"!=typeof n||isNaN(n))&&(n=null),a.slice(1).forEach((function(a){var i=e.cloneNode(!0);i.setAttribute("data-line-numbers",Rs.serializeHighlightSteps([a])),i.classList.add("fragment"),e.parentNode.appendChild(i),Rs.highlightLines(i),"number"==typeof n?(i.setAttribute("data-fragment-index",n),n+=1):i.removeAttribute("data-fragment-index"),i.addEventListener("visible",Rs.scrollHighlightedLineIntoView.bind(Rs,i,t)),i.addEventListener("hidden",Rs.scrollHighlightedLineIntoView.bind(Rs,i.previousSibling,t))})),e.removeAttribute("data-fragment-index"),e.setAttribute("data-line-numbers",Rs.serializeHighlightSteps([a[0]]))}var i="function"==typeof e.closest?e.closest("section:not(.stack)"):null;if(i){var r=function(){Rs.scrollHighlightedLineIntoView(e,t,!0),i.removeEventListener("visible",r)};i.addEventListener("visible",r)}Rs.highlightLines(e)}},scrollHighlightedLineIntoView:function(e,t,a){cancelAnimationFrame(t.animationFrameID),t.currentBlock&&(e.scrollTop=t.currentBlock.scrollTop),t.currentBlock=e;var n=this.getHighlightedLineBounds(e),i=e.offsetHeight,r=getComputedStyle(e);i-=parseInt(r.paddingTop)+parseInt(r.paddingBottom);var o=e.scrollTop,s=n.top+(Math.min(n.bottom-n.top,i)-i)/2,l=e.querySelector(".hljs-ln");if(l&&(s+=l.offsetTop-parseInt(r.paddingTop)),s=Math.max(Math.min(s,e.scrollHeight-i),0),!0===a||o===s)e.scrollTop=s;else{if(e.scrollHeight<=i)return;var c=0,_=function(){c=Math.min(c+.02,1),e.scrollTop=o+(s-o)*Rs.easeInOutQuart(c),c<1&&(t.animationFrameID=requestAnimationFrame(_))};_()}},easeInOutQuart:function(e){return e<.5?8*e*e*e*e:1-8*--e*e*e*e},getHighlightedLineBounds:function(e){var t=e.querySelectorAll(".highlight-line");if(0===t.length)return{top:0,bottom:0};var a=t[0],n=t[t.length-1];return{top:a.offsetTop,bottom:n.offsetTop+n.offsetHeight}},highlightLines:function(e,t){var a=Rs.deserializeHighlightSteps(t||e.getAttribute("data-line-numbers"));a.length&&a[0].forEach((function(t){var a=[];"number"==typeof t.end?a=[].slice.call(e.querySelectorAll("table tr:nth-child(n+"+t.start+"):nth-child(-n+"+t.end+")")):"number"==typeof t.start&&(a=[].slice.call(e.querySelectorAll("table tr:nth-child("+t.start+")"))),a.length&&(a.forEach((function(e){e.classList.add("highlight-line")})),e.classList.add("has-highlights"))}))},deserializeHighlightSteps:function(e){return(e=(e=e.replace(/\s/g,"")).split(Rs.HIGHLIGHT_STEP_DELIMITER)).map((function(e){return e.split(Rs.HIGHLIGHT_LINE_DELIMITER).map((function(e){if(/^[\d-]+$/.test(e)){e=e.split(Rs.HIGHLIGHT_LINE_RANGE_DELIMITER);var t=parseInt(e[0],10),a=parseInt(e[1],10);return isNaN(a)?{start:t}:{start:t,end:a}}return{}}))}))},serializeHighlightSteps:function(e){return e.map((function(e){return e.map((function(e){return"number"==typeof e.end?e.start+Rs.HIGHLIGHT_LINE_RANGE_DELIMITER+e.end:"number"==typeof e.start?e.start:""})).join(Rs.HIGHLIGHT_LINE_DELIMITER)})).join(Rs.HIGHLIGHT_STEP_DELIMITER)}};var Ns=()=>Rs;export{Ns as default}; +const Rs={id:"highlight",HIGHLIGHT_STEP_DELIMITER:"|",HIGHLIGHT_LINE_DELIMITER:",",HIGHLIGHT_LINE_RANGE_DELIMITER:"-",hljs:fs,init:function(e){let t=e.getConfig().highlight||{};t.highlightOnLoad="boolean"!=typeof t.highlightOnLoad||t.highlightOnLoad,t.escapeHTML="boolean"!=typeof t.escapeHTML||t.escapeHTML,Array.from(e.getRevealElement().querySelectorAll("pre code")).forEach((e=>{e.parentNode.classList.add("code-wrapper");let a=e.querySelector('script[type="text/template"]');a&&(e.textContent=a.innerHTML),e.hasAttribute("data-trim")&&"function"==typeof e.innerHTML.trim&&(e.innerHTML=function(e){function t(e){return e.replace(/^[\s\uFEFF\xA0]+/g,"")}function a(e){for(var t=e.split("\n"),a=0;a=0&&""===t[a].trim();a--)t.splice(a,1);return t.join("\n")}return function(e){var n=a(e.innerHTML).split("\n"),i=n.reduce((function(e,a){return a.length>0&&t(a).length>0&&e>a.length-t(a).length?a.length-t(a).length:e}),Number.POSITIVE_INFINITY);return n.map((function(e,t){return e.slice(i)})).join("\n")}(e)}(e)),t.escapeHTML&&!e.hasAttribute("data-noescape")&&(e.innerHTML=e.innerHTML.replace(//g,">")),e.addEventListener("focusout",(function(e){fs.highlightElement(e.currentTarget)}),!1)})),"function"==typeof t.beforeHighlight&&t.beforeHighlight(fs),t.highlightOnLoad&&Array.from(e.getRevealElement().querySelectorAll("pre code")).forEach((e=>{Rs.highlightBlock(e)})),e.on("pdf-ready",(function(){[].slice.call(e.getRevealElement().querySelectorAll("pre code[data-line-numbers].current-fragment")).forEach((function(e){Rs.scrollHighlightedLineIntoView(e,{},!0)}))}))},highlightBlock:function(e){if(fs.highlightElement(e),0!==e.innerHTML.trim().length&&e.hasAttribute("data-line-numbers")){fs.lineNumbersBlock(e,{singleLine:!0});var t={currentBlock:e},a=Rs.deserializeHighlightSteps(e.getAttribute("data-line-numbers"));if(a.length>1){var n=parseInt(e.getAttribute("data-fragment-index"),10);("number"!=typeof n||isNaN(n))&&(n=null),a.slice(1).forEach((function(a){var i=e.cloneNode(!0);i.setAttribute("data-line-numbers",Rs.serializeHighlightSteps([a])),i.classList.add("fragment"),e.parentNode.appendChild(i),Rs.highlightLines(i),"number"==typeof n?(i.setAttribute("data-fragment-index",n),n+=1):i.removeAttribute("data-fragment-index"),i.addEventListener("visible",Rs.scrollHighlightedLineIntoView.bind(Rs,i,t)),i.addEventListener("hidden",Rs.scrollHighlightedLineIntoView.bind(Rs,i.previousElementSibling,t))})),e.removeAttribute("data-fragment-index"),e.setAttribute("data-line-numbers",Rs.serializeHighlightSteps([a[0]]))}var i="function"==typeof e.closest?e.closest("section:not(.stack)"):null;if(i){var r=function(){Rs.scrollHighlightedLineIntoView(e,t,!0),i.removeEventListener("visible",r)};i.addEventListener("visible",r)}Rs.highlightLines(e)}},scrollHighlightedLineIntoView:function(e,t,a){cancelAnimationFrame(t.animationFrameID),t.currentBlock&&(e.scrollTop=t.currentBlock.scrollTop),t.currentBlock=e;var n=this.getHighlightedLineBounds(e),i=e.offsetHeight,r=getComputedStyle(e);i-=parseInt(r.paddingTop)+parseInt(r.paddingBottom);var o=e.scrollTop,s=n.top+(Math.min(n.bottom-n.top,i)-i)/2,l=e.querySelector(".hljs-ln");if(l&&(s+=l.offsetTop-parseInt(r.paddingTop)),s=Math.max(Math.min(s,e.scrollHeight-i),0),!0===a||o===s)e.scrollTop=s;else{if(e.scrollHeight<=i)return;var c=0,_=function(){c=Math.min(c+.02,1),e.scrollTop=o+(s-o)*Rs.easeInOutQuart(c),c<1&&(t.animationFrameID=requestAnimationFrame(_))};_()}},easeInOutQuart:function(e){return e<.5?8*e*e*e*e:1-8*--e*e*e*e},getHighlightedLineBounds:function(e){var t=e.querySelectorAll(".highlight-line");if(0===t.length)return{top:0,bottom:0};var a=t[0],n=t[t.length-1];return{top:a.offsetTop,bottom:n.offsetTop+n.offsetHeight}},highlightLines:function(e,t){var a=Rs.deserializeHighlightSteps(t||e.getAttribute("data-line-numbers"));a.length&&a[0].forEach((function(t){var a=[];"number"==typeof t.end?a=[].slice.call(e.querySelectorAll("table tr:nth-child(n+"+t.start+"):nth-child(-n+"+t.end+")")):"number"==typeof t.start&&(a=[].slice.call(e.querySelectorAll("table tr:nth-child("+t.start+")"))),a.length&&(a.forEach((function(e){e.classList.add("highlight-line")})),e.classList.add("has-highlights"))}))},deserializeHighlightSteps:function(e){return(e=(e=e.replace(/\s/g,"")).split(Rs.HIGHLIGHT_STEP_DELIMITER)).map((function(e){return e.split(Rs.HIGHLIGHT_LINE_DELIMITER).map((function(e){if(/^[\d-]+$/.test(e)){e=e.split(Rs.HIGHLIGHT_LINE_RANGE_DELIMITER);var t=parseInt(e[0],10),a=parseInt(e[1],10);return isNaN(a)?{start:t}:{start:t,end:a}}return{}}))}))},serializeHighlightSteps:function(e){return e.map((function(e){return e.map((function(e){return"number"==typeof e.end?e.start+Rs.HIGHLIGHT_LINE_RANGE_DELIMITER+e.end:"number"==typeof e.start?e.start:""})).join(Rs.HIGHLIGHT_LINE_DELIMITER)})).join(Rs.HIGHLIGHT_STEP_DELIMITER)}};var Ns=()=>Rs;export{Ns as default}; diff --git a/plugin/highlight/highlight.js b/plugin/highlight/highlight.js index a73b409c04f..e78c45fc3d3 100644 --- a/plugin/highlight/highlight.js +++ b/plugin/highlight/highlight.js @@ -2,4 +2,4 @@ /*! * reveal.js plugin that adds syntax highlight support. */ -const Rs={id:"highlight",HIGHLIGHT_STEP_DELIMITER:"|",HIGHLIGHT_LINE_DELIMITER:",",HIGHLIGHT_LINE_RANGE_DELIMITER:"-",hljs:fs,init:function(e){let t=e.getConfig().highlight||{};t.highlightOnLoad="boolean"!=typeof t.highlightOnLoad||t.highlightOnLoad,t.escapeHTML="boolean"!=typeof t.escapeHTML||t.escapeHTML,Array.from(e.getRevealElement().querySelectorAll("pre code")).forEach((e=>{e.parentNode.classList.add("code-wrapper");let a=e.querySelector('script[type="text/template"]');a&&(e.textContent=a.innerHTML),e.hasAttribute("data-trim")&&"function"==typeof e.innerHTML.trim&&(e.innerHTML=function(e){function t(e){return e.replace(/^[\s\uFEFF\xA0]+/g,"")}function a(e){for(var t=e.split("\n"),a=0;a=0&&""===t[a].trim();a--)t.splice(a,1);return t.join("\n")}return function(e){var n=a(e.innerHTML).split("\n"),i=n.reduce((function(e,a){return a.length>0&&t(a).length>0&&e>a.length-t(a).length?a.length-t(a).length:e}),Number.POSITIVE_INFINITY);return n.map((function(e,t){return e.slice(i)})).join("\n")}(e)}(e)),t.escapeHTML&&!e.hasAttribute("data-noescape")&&(e.innerHTML=e.innerHTML.replace(//g,">")),e.addEventListener("focusout",(function(e){fs.highlightElement(e.currentTarget)}),!1)})),"function"==typeof t.beforeHighlight&&t.beforeHighlight(fs),t.highlightOnLoad&&Array.from(e.getRevealElement().querySelectorAll("pre code")).forEach((e=>{Rs.highlightBlock(e)})),e.on("pdf-ready",(function(){[].slice.call(e.getRevealElement().querySelectorAll("pre code[data-line-numbers].current-fragment")).forEach((function(e){Rs.scrollHighlightedLineIntoView(e,{},!0)}))}))},highlightBlock:function(e){if(fs.highlightElement(e),0!==e.innerHTML.trim().length&&e.hasAttribute("data-line-numbers")){fs.lineNumbersBlock(e,{singleLine:!0});var t={currentBlock:e},a=Rs.deserializeHighlightSteps(e.getAttribute("data-line-numbers"));if(a.length>1){var n=parseInt(e.getAttribute("data-fragment-index"),10);("number"!=typeof n||isNaN(n))&&(n=null),a.slice(1).forEach((function(a){var i=e.cloneNode(!0);i.setAttribute("data-line-numbers",Rs.serializeHighlightSteps([a])),i.classList.add("fragment"),e.parentNode.appendChild(i),Rs.highlightLines(i),"number"==typeof n?(i.setAttribute("data-fragment-index",n),n+=1):i.removeAttribute("data-fragment-index"),i.addEventListener("visible",Rs.scrollHighlightedLineIntoView.bind(Rs,i,t)),i.addEventListener("hidden",Rs.scrollHighlightedLineIntoView.bind(Rs,i.previousSibling,t))})),e.removeAttribute("data-fragment-index"),e.setAttribute("data-line-numbers",Rs.serializeHighlightSteps([a[0]]))}var i="function"==typeof e.closest?e.closest("section:not(.stack)"):null;if(i){var r=function(){Rs.scrollHighlightedLineIntoView(e,t,!0),i.removeEventListener("visible",r)};i.addEventListener("visible",r)}Rs.highlightLines(e)}},scrollHighlightedLineIntoView:function(e,t,a){cancelAnimationFrame(t.animationFrameID),t.currentBlock&&(e.scrollTop=t.currentBlock.scrollTop),t.currentBlock=e;var n=this.getHighlightedLineBounds(e),i=e.offsetHeight,r=getComputedStyle(e);i-=parseInt(r.paddingTop)+parseInt(r.paddingBottom);var o=e.scrollTop,s=n.top+(Math.min(n.bottom-n.top,i)-i)/2,l=e.querySelector(".hljs-ln");if(l&&(s+=l.offsetTop-parseInt(r.paddingTop)),s=Math.max(Math.min(s,e.scrollHeight-i),0),!0===a||o===s)e.scrollTop=s;else{if(e.scrollHeight<=i)return;var c=0,_=function(){c=Math.min(c+.02,1),e.scrollTop=o+(s-o)*Rs.easeInOutQuart(c),c<1&&(t.animationFrameID=requestAnimationFrame(_))};_()}},easeInOutQuart:function(e){return e<.5?8*e*e*e*e:1-8*--e*e*e*e},getHighlightedLineBounds:function(e){var t=e.querySelectorAll(".highlight-line");if(0===t.length)return{top:0,bottom:0};var a=t[0],n=t[t.length-1];return{top:a.offsetTop,bottom:n.offsetTop+n.offsetHeight}},highlightLines:function(e,t){var a=Rs.deserializeHighlightSteps(t||e.getAttribute("data-line-numbers"));a.length&&a[0].forEach((function(t){var a=[];"number"==typeof t.end?a=[].slice.call(e.querySelectorAll("table tr:nth-child(n+"+t.start+"):nth-child(-n+"+t.end+")")):"number"==typeof t.start&&(a=[].slice.call(e.querySelectorAll("table tr:nth-child("+t.start+")"))),a.length&&(a.forEach((function(e){e.classList.add("highlight-line")})),e.classList.add("has-highlights"))}))},deserializeHighlightSteps:function(e){return(e=(e=e.replace(/\s/g,"")).split(Rs.HIGHLIGHT_STEP_DELIMITER)).map((function(e){return e.split(Rs.HIGHLIGHT_LINE_DELIMITER).map((function(e){if(/^[\d-]+$/.test(e)){e=e.split(Rs.HIGHLIGHT_LINE_RANGE_DELIMITER);var t=parseInt(e[0],10),a=parseInt(e[1],10);return isNaN(a)?{start:t}:{start:t,end:a}}return{}}))}))},serializeHighlightSteps:function(e){return e.map((function(e){return e.map((function(e){return"number"==typeof e.end?e.start+Rs.HIGHLIGHT_LINE_RANGE_DELIMITER+e.end:"number"==typeof e.start?e.start:""})).join(Rs.HIGHLIGHT_LINE_DELIMITER)})).join(Rs.HIGHLIGHT_STEP_DELIMITER)}};return()=>Rs})); +const Rs={id:"highlight",HIGHLIGHT_STEP_DELIMITER:"|",HIGHLIGHT_LINE_DELIMITER:",",HIGHLIGHT_LINE_RANGE_DELIMITER:"-",hljs:fs,init:function(e){let t=e.getConfig().highlight||{};t.highlightOnLoad="boolean"!=typeof t.highlightOnLoad||t.highlightOnLoad,t.escapeHTML="boolean"!=typeof t.escapeHTML||t.escapeHTML,Array.from(e.getRevealElement().querySelectorAll("pre code")).forEach((e=>{e.parentNode.classList.add("code-wrapper");let a=e.querySelector('script[type="text/template"]');a&&(e.textContent=a.innerHTML),e.hasAttribute("data-trim")&&"function"==typeof e.innerHTML.trim&&(e.innerHTML=function(e){function t(e){return e.replace(/^[\s\uFEFF\xA0]+/g,"")}function a(e){for(var t=e.split("\n"),a=0;a=0&&""===t[a].trim();a--)t.splice(a,1);return t.join("\n")}return function(e){var n=a(e.innerHTML).split("\n"),i=n.reduce((function(e,a){return a.length>0&&t(a).length>0&&e>a.length-t(a).length?a.length-t(a).length:e}),Number.POSITIVE_INFINITY);return n.map((function(e,t){return e.slice(i)})).join("\n")}(e)}(e)),t.escapeHTML&&!e.hasAttribute("data-noescape")&&(e.innerHTML=e.innerHTML.replace(//g,">")),e.addEventListener("focusout",(function(e){fs.highlightElement(e.currentTarget)}),!1)})),"function"==typeof t.beforeHighlight&&t.beforeHighlight(fs),t.highlightOnLoad&&Array.from(e.getRevealElement().querySelectorAll("pre code")).forEach((e=>{Rs.highlightBlock(e)})),e.on("pdf-ready",(function(){[].slice.call(e.getRevealElement().querySelectorAll("pre code[data-line-numbers].current-fragment")).forEach((function(e){Rs.scrollHighlightedLineIntoView(e,{},!0)}))}))},highlightBlock:function(e){if(fs.highlightElement(e),0!==e.innerHTML.trim().length&&e.hasAttribute("data-line-numbers")){fs.lineNumbersBlock(e,{singleLine:!0});var t={currentBlock:e},a=Rs.deserializeHighlightSteps(e.getAttribute("data-line-numbers"));if(a.length>1){var n=parseInt(e.getAttribute("data-fragment-index"),10);("number"!=typeof n||isNaN(n))&&(n=null),a.slice(1).forEach((function(a){var i=e.cloneNode(!0);i.setAttribute("data-line-numbers",Rs.serializeHighlightSteps([a])),i.classList.add("fragment"),e.parentNode.appendChild(i),Rs.highlightLines(i),"number"==typeof n?(i.setAttribute("data-fragment-index",n),n+=1):i.removeAttribute("data-fragment-index"),i.addEventListener("visible",Rs.scrollHighlightedLineIntoView.bind(Rs,i,t)),i.addEventListener("hidden",Rs.scrollHighlightedLineIntoView.bind(Rs,i.previousElementSibling,t))})),e.removeAttribute("data-fragment-index"),e.setAttribute("data-line-numbers",Rs.serializeHighlightSteps([a[0]]))}var i="function"==typeof e.closest?e.closest("section:not(.stack)"):null;if(i){var r=function(){Rs.scrollHighlightedLineIntoView(e,t,!0),i.removeEventListener("visible",r)};i.addEventListener("visible",r)}Rs.highlightLines(e)}},scrollHighlightedLineIntoView:function(e,t,a){cancelAnimationFrame(t.animationFrameID),t.currentBlock&&(e.scrollTop=t.currentBlock.scrollTop),t.currentBlock=e;var n=this.getHighlightedLineBounds(e),i=e.offsetHeight,r=getComputedStyle(e);i-=parseInt(r.paddingTop)+parseInt(r.paddingBottom);var o=e.scrollTop,s=n.top+(Math.min(n.bottom-n.top,i)-i)/2,l=e.querySelector(".hljs-ln");if(l&&(s+=l.offsetTop-parseInt(r.paddingTop)),s=Math.max(Math.min(s,e.scrollHeight-i),0),!0===a||o===s)e.scrollTop=s;else{if(e.scrollHeight<=i)return;var c=0,_=function(){c=Math.min(c+.02,1),e.scrollTop=o+(s-o)*Rs.easeInOutQuart(c),c<1&&(t.animationFrameID=requestAnimationFrame(_))};_()}},easeInOutQuart:function(e){return e<.5?8*e*e*e*e:1-8*--e*e*e*e},getHighlightedLineBounds:function(e){var t=e.querySelectorAll(".highlight-line");if(0===t.length)return{top:0,bottom:0};var a=t[0],n=t[t.length-1];return{top:a.offsetTop,bottom:n.offsetTop+n.offsetHeight}},highlightLines:function(e,t){var a=Rs.deserializeHighlightSteps(t||e.getAttribute("data-line-numbers"));a.length&&a[0].forEach((function(t){var a=[];"number"==typeof t.end?a=[].slice.call(e.querySelectorAll("table tr:nth-child(n+"+t.start+"):nth-child(-n+"+t.end+")")):"number"==typeof t.start&&(a=[].slice.call(e.querySelectorAll("table tr:nth-child("+t.start+")"))),a.length&&(a.forEach((function(e){e.classList.add("highlight-line")})),e.classList.add("has-highlights"))}))},deserializeHighlightSteps:function(e){return(e=(e=e.replace(/\s/g,"")).split(Rs.HIGHLIGHT_STEP_DELIMITER)).map((function(e){return e.split(Rs.HIGHLIGHT_LINE_DELIMITER).map((function(e){if(/^[\d-]+$/.test(e)){e=e.split(Rs.HIGHLIGHT_LINE_RANGE_DELIMITER);var t=parseInt(e[0],10),a=parseInt(e[1],10);return isNaN(a)?{start:t}:{start:t,end:a}}return{}}))}))},serializeHighlightSteps:function(e){return e.map((function(e){return e.map((function(e){return"number"==typeof e.end?e.start+Rs.HIGHLIGHT_LINE_RANGE_DELIMITER+e.end:"number"==typeof e.start?e.start:""})).join(Rs.HIGHLIGHT_LINE_DELIMITER)})).join(Rs.HIGHLIGHT_STEP_DELIMITER)}};return()=>Rs})); diff --git a/plugin/highlight/plugin.js b/plugin/highlight/plugin.js index 46528bf7b4e..26a7f93ba59 100644 --- a/plugin/highlight/plugin.js +++ b/plugin/highlight/plugin.js @@ -138,7 +138,7 @@ const Plugin = { // Scroll highlights into view as we step through them fragmentBlock.addEventListener( 'visible', Plugin.scrollHighlightedLineIntoView.bind( Plugin, fragmentBlock, scrollState ) ); - fragmentBlock.addEventListener( 'hidden', Plugin.scrollHighlightedLineIntoView.bind( Plugin, fragmentBlock.previousSibling, scrollState ) ); + fragmentBlock.addEventListener( 'hidden', Plugin.scrollHighlightedLineIntoView.bind( Plugin, fragmentBlock.previousElementSibling, scrollState ) ); } );