Improves changeset schemas and fix moved diff syntax highlighting

This commit is contained in:
Sebastian Martinez
2023-11-28 10:39:32 +01:00
parent aa7a1b7040
commit 1167dcfab6
2 changed files with 20 additions and 8 deletions
+16 -5
View File
@@ -16,7 +16,6 @@ import {
literal,
number,
object,
optional,
record,
string,
union,
@@ -151,19 +150,31 @@ const diffCopiedChangesetSchema = object({
const diffMovedChangesetSchema = diffCopiedChangesetSchema.merge(
object({
old: optional(diffFileSchema),
new: optional(diffFileSchema),
diff: optional(diffContentSchema),
current: diffFileSchema,
}),
);
const diffMovedWithModificationsChangesetSchema =
diffCopiedChangesetSchema.merge(
object({
old: diffFileSchema,
new: diffFileSchema,
diff: diffContentSchema,
}),
);
type Diff = z.infer<typeof diffSchema>;
const diffSchema = object({
added: array(diffAddedChangesetSchema),
deleted: array(diffDeletedChangesetSchema),
modified: array(diffModifiedChangesetSchema),
moved: array(diffMovedChangesetSchema),
moved: array(
union([
diffMovedChangesetSchema,
diffMovedWithModificationsChangesetSchema,
]),
),
copied: array(diffCopiedChangesetSchema),
stats: object({
filesChanged: number(),
+4 -3
View File
@@ -154,18 +154,19 @@
</div>
{/each}
{#each diff.moved as file}
{#if file.diff}
{#if "diff" in file}
<div use:intersection={observer} id={"observer:" + file.newPath}>
<FileDiff
{projectId}
{baseUrl}
{revision}
{expanded}
content=""
content={files[file.new.oid]?.content}
oldContent={files[file.old.oid]?.content}
visible={filesVisibility.has(file.newPath)}
filePath={file.newPath}
oldFilePath={file.oldPath}
fileDiff={file.diff}
fileDiff={{ ...file.diff, type: getFileType(file.diff, file.new) }}
headerBadgeCaption="moved" />
</div>
{:else}