Compare commits

..

1 commit

Author SHA1 Message Date
Julian Lohrber
a5bf872a42
Merge 70bcc3fa77 into 81818a19d1 2024-12-28 15:17:44 +01:00
2 changed files with 22 additions and 42 deletions

View file

@ -236,7 +236,8 @@ export function copyYAMLComments(doc : Document, src : Document) {
/**
* Copy yaml comments from srcItems to items
* Attempts to preserve comments by matching content rather than just array indices
* Typescript is super annoying here, so I have to use any here
* TODO: Since comments are belong to the array index, the comments will be lost if the order of the items is changed or removed or added.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function copyYAMLCommentsItems(items : any, srcItems : any) {
@ -244,23 +245,16 @@ function copyYAMLCommentsItems(items: any, srcItems: any) {
return;
}
// First pass - try to match items by their content
for (let i = 0; i < items.length; i++) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const item : any = items[i];
// Try to find matching source item by content
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const srcIndex = srcItems.findIndex((srcItem: any) =>
JSON.stringify(srcItem.value) === JSON.stringify(item.value) &&
JSON.stringify(srcItem.key) === JSON.stringify(item.key)
);
const srcItem : any = srcItems[i];
if (srcIndex !== -1) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const srcItem: any = srcItems[srcIndex];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const nextSrcItem: any = srcItems[srcIndex + 1];
if (!srcItem) {
continue;
}
if (item.key && srcItem.key) {
item.key.comment = srcItem.key.comment;
@ -271,20 +265,6 @@ function copyYAMLCommentsItems(items: any, srcItems: any) {
item.comment = srcItem.comment;
}
// Handle comments between array items
if (nextSrcItem && nextSrcItem.commentBefore) {
if (items[i + 1]) {
items[i + 1].commentBefore = nextSrcItem.commentBefore;
}
}
// Handle trailing comments after array items
if (srcItem.value && srcItem.value.comment) {
if (item.value) {
item.value.comment = srcItem.value.comment;
}
}
if (item.value && srcItem.value) {
if (typeof item.value === "object" && typeof srcItem.value === "object") {
item.value.comment = srcItem.value.comment;
@ -297,7 +277,6 @@ function copyYAMLCommentsItems(items: any, srcItems: any) {
}
}
}
}
/**
* Possible Inputs:

View file

@ -247,6 +247,7 @@ export default {
<style scoped lang="scss">
.main-terminal {
height: 100%;
overflow-x: scroll;
}
</style>