Skip to content

Commit

Permalink
Merge pull request #5012 from dodona-edu/fix/error-not-on-last-line
Browse files Browse the repository at this point in the history
Show machine annotations on the last line if index out of range
  • Loading branch information
jorg-vr authored Sep 27, 2023
2 parents 2b0338b + 8a00970 commit c1f8ada
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/assets/javascripts/state/MachineAnnotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { State } from "state/state_system/State";
import { stateProperty } from "state/state_system/StateProperty";
import { StateMap } from "state/state_system/StateMap";
import { createStateFromInterface } from "state/state_system/CreateStateFromInterface";
import { submissionState } from "state/Submissions";

export interface MachineAnnotationData {
type: AnnotationType;
Expand Down Expand Up @@ -30,7 +31,13 @@ class MachineAnnotationState extends State {
for (const data of annotations) {
const annotation = new MachineAnnotation(data);
const markedLength = annotation.rows ?? 1;
const line = annotation.row ? annotation.row + markedLength : 1;
let line = annotation.row ? annotation.row + markedLength : 1;

// show annotation on the last line if it is out of range
if (line > submissionState.codeByLine.length) {
line = submissionState.codeByLine.length;
}

if (this.byLine.has(line)) {
this.byLine.get(line)?.push(annotation);
} else {
Expand Down

0 comments on commit c1f8ada

Please sign in to comment.