Skip to content

Commit

Permalink
Also compare other attributes for md preview updates
Browse files Browse the repository at this point in the history
Fixes #136816
  • Loading branch information
mjbvz committed Nov 10, 2021
1 parent 84eca12 commit 71f615b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions extensions/markdown-language-features/preview-src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ window.addEventListener('message', async event => {
root.replaceWith(newContent.querySelector('.markdown-body')!);
documentResource = event.data.source;
} else {
// Compare two elements but skip `data-line`
const areEqual = (a: Element, b: Element): boolean => {
if (a.isEqualNode(b)) {
return true;
Expand All @@ -143,6 +144,23 @@ window.addEventListener('message', async event => {
return false;
}

const aAttrs = a.attributes;
const bAttrs = b.attributes;
if (aAttrs.length !== bAttrs.length) {
return false;
}

for (let i = 0; i < aAttrs.length; ++i) {
const aAttr = aAttrs[i];
const bAttr = bAttrs[i];
if (aAttr.name !== bAttr.name) {
return false;
}
if (aAttr.value !== bAttr.value && aAttr.name !== 'data-line') {
return false;
}
}

const aChildren = Array.from(a.children);
const bChildren = Array.from(b.children);

Expand Down

0 comments on commit 71f615b

Please sign in to comment.