Skip to content

Commit

Permalink
Fix looking up clickable URLs in code viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Jul 29, 2023
1 parent 81b2fce commit 223e230
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/js/code-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,25 @@ async function start() {
});

dom.on('#content', 'click', '.cm-href', ev => {
setURL(ev.target.textContent);
const target = ev.target;
const urlParts = [ target.textContent ];
let previous = target;
for (;;) {
previous = previous.previousSibling;
if ( previous === null ) { break; }
if ( previous.nodeType !== 1 ) { break; }
if ( previous.classList.contains('cm-href') === false ) { break; }
urlParts.unshift(previous.textContent);
}
let next = target;
for (;;) {
next = next.nextSibling;
if ( next === null ) { break; }
if ( next.nodeType !== 1 ) { break; }
if ( next.classList.contains('cm-href') === false ) { break; }
urlParts.push(next.textContent);
}
setURL(urlParts.join(''));
});
}

Expand Down

0 comments on commit 223e230

Please sign in to comment.