From aecae8e2bf8f32c4caa30cbc029136c148503e91 Mon Sep 17 00:00:00 2001 From: estib Date: Tue, 17 Sep 2024 17:15:09 +0200 Subject: [PATCH] fix: File section max line number & simplify hunk header calculation - Fix a bug in which the max lines would not be taken into account when checking what the biggest line number in a hunk section. - Simplify the calculation of the header width for the HunkDiff component --- apps/desktop/src/lib/hunk/HunkDiff.svelte | 17 ++++++++--------- apps/desktop/src/lib/utils/fileSections.ts | 14 ++++---------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/apps/desktop/src/lib/hunk/HunkDiff.svelte b/apps/desktop/src/lib/hunk/HunkDiff.svelte index 6806f8912..aa0859656 100644 --- a/apps/desktop/src/lib/hunk/HunkDiff.svelte +++ b/apps/desktop/src/lib/hunk/HunkDiff.svelte @@ -65,6 +65,7 @@ let tableWidth = $state(0); let tableHeight = $state(0); + let numberHeaderWidth = $state(0); const selected = $derived($selectedOwnership?.isSelected(hunk.filePath, hunk.id) ?? false); let isSelected = $derived(selectable && selected); @@ -345,6 +346,7 @@ }} >
{`@@ -${hunkLineInfo.beforLineStart},${hunkLineInfo.beforeLineCount} +${hunkLineInfo.afterLineStart},${hunkLineInfo.afterLineCount} @@`} @@ -385,8 +385,7 @@
@@ -513,8 +512,8 @@ pointer-events: none; position: absolute; top: 0; - left: calc(var(--number-col-width) * 2); - width: calc(var(--table-width) - var(--number-col-width) * 2); + left: var(--number-col-width); + width: calc(var(--table-width) - var(--number-col-width)); height: var(--table-height); border-bottom: 1px solid var(--clr-border-2); border-right: 1px solid var(--clr-border-2); @@ -524,8 +523,8 @@ .table__title-content { position: absolute; top: var(--top); - left: calc(var(--number-col-width) * 2); - width: calc(var(--table-width) - var(--number-col-width) * 2); + left: var(--number-col-width); + width: calc(var(--table-width) - var(--number-col-width)); height: calc(100% + var(--border-width) * 2); box-sizing: border-box; font-family: var(--mono-font-family); diff --git a/apps/desktop/src/lib/utils/fileSections.ts b/apps/desktop/src/lib/utils/fileSections.ts index 994a34d8f..67ed82343 100644 --- a/apps/desktop/src/lib/utils/fileSections.ts +++ b/apps/desktop/src/lib/utils/fileSections.ts @@ -33,19 +33,13 @@ export class HunkSection { hasConflictMarkers!: boolean; get maxLineNumber(): number { - // if (section instanceof ContentSection) { - // return Math.max( - // section.lines[section.lines.length - 1].afterLineNumber || 0, - // section.lines[section.lines.length - 1].afterLineNumber || 0 - // ); - // } const lastSection = this.subSections[this.subSections.length - 1]; if (!lastSection) { return 0; } return Math.max( - lastSection.lines[lastSection.lines.length - 1]?.afterLineNumber || 0, - lastSection.lines[lastSection.lines.length - 1]?.afterLineNumber || 0 + lastSection.lines[lastSection.lines.length - 1]?.afterLineNumber ?? 0, + lastSection.lines[lastSection.lines.length - 1]?.beforeLineNumber ?? 0 ); } } @@ -57,8 +51,8 @@ export class ContentSection { get maxLineNumber(): number { return Math.max( - this.lines[this.lines.length - 1]?.afterLineNumber || 0, - this.lines[this.lines.length - 1]?.afterLineNumber || 0 + this.lines[this.lines.length - 1]?.afterLineNumber ?? 0, + this.lines[this.lines.length - 1]?.beforeLineNumber ?? 0 ); } }