Skip to content

Commit

Permalink
Update fixture to include new JS
Browse files Browse the repository at this point in the history
  • Loading branch information
gibson042 committed Aug 27, 2024
1 parent ce68621 commit 3deecb1
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions test/baselines/generated-reference/assets-inline.html
Original file line number Diff line number Diff line change
Expand Up @@ -1488,20 +1488,31 @@
// Omit indendation when copying a single algorithm step.
document.addEventListener('copy', evt => {
const selection = getSelection();
const singleRange = selection?.rangeCount === 1 && selection.getRangeAt(0);
const container = singleRange?.commonAncestorContainer;
if (!container?.querySelector("span[aria-hidden='true']")) {
return;
const doc = document.implementation.createHTMLDocument('');
const domRoot = doc.createElement('div');
const html = evt.clipboardData.getData('text/html');
if (html) {
domRoot.innerHTML = html;
} else {
const selection = getSelection();
const singleRange = selection?.rangeCount === 1 && selection.getRangeAt(0);
const container = singleRange?.commonAncestorContainer;
if (!container?.querySelector?.("span[aria-hidden='true']")) {
return;
}
domRoot.append(singleRange.cloneContents());
}
const clone = document.createElement('div');
clone.append(singleRange.cloneContents());
const lastHidden = [...clone.querySelectorAll("span[aria-hidden='true']")].at(-1);
if (lastHidden.previousSibling || lastHidden.parentNode !== clone) {
const hiddenElems = [...domRoot.querySelectorAll("span[aria-hidden='true']")];
const lastHidden = hiddenElems.at(-1);
if (lastHidden?.parentNode !== domRoot || lastHidden.previousSibling) {
// Manipulation is not appropriate, either because there is more than one
// hidden element or because the only one is not at the beginning.
return;
}
evt.clipboardData.setData('text/plain', clone.textContent.trimStart());
evt.clipboardData.setData('text/html', clone.innerHTML);
evt.clipboardData.setData('text/plain', domRoot.textContent.trimStart());
if (!html) {
evt.clipboardData.setData('text/html', domRoot.innerHTML);
}
evt.preventDefault();
});
Expand Down

0 comments on commit 3deecb1

Please sign in to comment.