Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constrain annotations to start within the length of the line when rendering #4921

Merged
merged 2 commits into from
Aug 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions app/assets/javascripts/components/annotations/line_of_code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
.sort(compareAnnotationOrders);
}

hasValidColumn(annotation: Annotation): boolean {
return annotation.column !== undefined && annotation.column !== null && annotation.column >= 0 && annotation.column < this.codeLength;
}

/**
* Calculates the range of the code that is covered by the given annotation.
* If the annotation spans multiple lines, the range will be the whole line unless this is the first or last line.
Expand All @@ -81,12 +85,17 @@

let start = 0;
if (this.row === firstRow) {
start = annotation.column || 0;
// In rare cases, machine annotations start past the end of the line, resulting in errors if we don't constrain them to be in the line
if (this.hasValidColumn(annotation)) {
start = annotation.column;

Check warning on line 90 in app/assets/javascripts/components/annotations/line_of_code.ts

View check run for this annotation

Codecov / codecov/patch

app/assets/javascripts/components/annotations/line_of_code.ts#L90

Added line #L90 was not covered by tests
} else {
start = 0;
}
}

let length = this.codeLength - start;
if (this.row === lastRow) {
if (annotation.column !== undefined && annotation.column !== null) {
if (this.hasValidColumn(annotation)) {
const defaultLength = isMachineAnnotation ? 0 : this.codeLength - start;
length = annotation.columns || defaultLength;
}
Expand Down