diff --git a/src/lib/components/DiffViewer.svelte b/src/lib/components/DiffViewer.svelte index e27d80bd4..5b2d95d91 100644 --- a/src/lib/components/DiffViewer.svelte +++ b/src/lib/components/DiffViewer.svelte @@ -14,6 +14,8 @@ let middleDiff = ''; let currentOffset = 0; + let htmlTagRegex = /(<([^>]+)>)/gi; + $: if (diff) { middleDiff = ''; currentDiff = ''; @@ -28,15 +30,16 @@ let diffLines = middleDiff.split('
'); diffLines.forEach((line, index) => { lineClass = 'lineContext bg-zinc-800'; + let firstChar = line.replace(htmlTagRegex, '').slice(0, 1); if (index < 4) { lineClass = 'lineDiff bg-zinc-900 text-zinc-500'; } else if (line.slice(0, 2) == '@@') { lineClass = 'lineSplit bg-blue-900'; - } else if (line.slice(0, 1) == '+') { + } else if (firstChar == '+') { if (!line.includes('+++')) { lineClass = 'lineSplit bg-green-900'; } - } else if (line.slice(0, 1) == '-') { + } else if (firstChar == '-') { if (!line.includes('---')) { lineClass = 'lineSplit bg-red-900'; } diff --git a/src/routes/projects/[projectId]/commit/+page.svelte b/src/routes/projects/[projectId]/commit/+page.svelte index 16925fa94..de00f4268 100644 --- a/src/routes/projects/[projectId]/commit/+page.svelte +++ b/src/routes/projects/[projectId]/commit/+page.svelte @@ -76,21 +76,24 @@ let currentPath = ''; let currentDiff = ''; - let addedContents = ''; + let fileContents = ''; + let fileContentsStatus = ''; + // Replace HTML tags with an empty string function selectPath(path) { currentDiff = ''; - addedContents = ''; + fileContents = ''; if (gitDiff[path]) { currentPath = path; currentDiff = gitDiff[path]; } else { let file = $filesStatus.filter((file) => file.path === path)[0]; - if (file && file.status === 'added') { + if (file) { + fileContentsStatus = file.status; getFile({ projectId: $project?.id, path: path }).then((contents) => { currentPath = path; - addedContents = contents; + fileContents = contents; }); } } @@ -278,8 +281,9 @@
{#if currentDiff} - {:else if addedContents} -
{addedContents}
+ {:else if fileContents} +
{fileContents}
{:else}
Select a file to view changes.
{/if}