Skip to content

Commit

Permalink
[#66130] add function for checking previous elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Trzcin committed Sep 25, 2024
1 parent 6dd6f41 commit 931ce89
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/extensions/syncDualPane.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,11 @@ export function handlePreviewClickToScroll(/** @type {{ target: HTMLElement }} *
let id = ev.target.getAttribute("data-line-id");
let elem = ev.target;
if (!id) {
// check parents
outer: while (elem.tagName !== "HTML-CHUNK") {
// check parents and siblings
while (elem.tagName !== "HTML-CHUNK") {
const parent = elem.parentElement;
// check siblings
while (elem != null) {
id = elem.getAttribute("data-line-id");
if (id) break outer;
elem = elem.previousElementSibling;
}
[id, elem] = findSoruceMappedPreviousElement(elem);
if (id) break;
elem = parent;
}
}
Expand Down Expand Up @@ -102,3 +98,14 @@ export function handlePreviewClickToScroll(/** @type {{ target: HTMLElement }} *
setCursor();
}
}

function findSoruceMappedPreviousElement(startingElem) {
let elem = startingElem;
while (elem != null) {
const id = elem.getAttribute("data-line-id");
if (id) return [id, elem];
elem = elem.previousElementSibling;
}

return [undefined, elem];
}

0 comments on commit 931ce89

Please sign in to comment.