Skip to content

Commit db31add

Browse files
committed
Fix error reporting offsets
1 parent 7e96316 commit db31add

File tree

5 files changed

+26
-17
lines changed

5 files changed

+26
-17
lines changed

src/disk.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import CodeMirror from "codemirror";
21
import * as output from "./output";
32
import EventEmitter from "events";
43

src/frames.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type FrameMutations = {
77
height?: number;
88
opacity?: number;
99
strokes?: Stroke[];
10+
color?: string;
1011
foreground?: string;
1112
background?: string;
1213
speed?: number;
@@ -23,6 +24,7 @@ export class Frame {
2324
readonly height = 0,
2425
readonly opacity = 1,
2526
readonly strokes = [] as Stroke[],
27+
readonly color = "",
2628
readonly foreground = "",
2729
readonly background = "",
2830
readonly speed = 100,
@@ -34,14 +36,16 @@ export class Frame {
3436

3537
with(properties: FrameMutations): Frame {
3638
return new Frame(
37-
properties.position || this.position,
38-
properties.facing !== undefined ? properties.facing : this.facing,
39-
properties.height !== undefined ? properties.height : this.height,
40-
properties.opacity !== undefined ? properties.opacity : this.opacity,
41-
properties.strokes || this.strokes,
42-
properties.foreground !== undefined ? properties.foreground : this.foreground,
43-
properties.background !== undefined ? properties.background : this.background,
44-
properties.speed !== undefined ? properties.speed : this.speed);
39+
properties.position ?? this.position,
40+
properties.facing ?? this.facing,
41+
properties.height ?? this.height,
42+
properties.opacity ?? this.opacity,
43+
properties.strokes ?? this.strokes,
44+
properties.color ?? this.color,
45+
properties.foreground ?? this.foreground,
46+
properties.background ?? this.background,
47+
properties.speed ?? this.speed,
48+
);
4549
}
4650
}
4751

@@ -51,7 +55,8 @@ export class Animation {
5155

5256
constructor(
5357
readonly duration: number,
54-
readonly update: (delta: number, keyFrame: Frame) => Frame) { }
58+
readonly update: (delta: number, keyFrame: Frame) => Frame,
59+
) { }
5560

5661
get currentFrame(): Frame {
5762
return this.update(this.elapsed / this.duration, this.keyFrame);

src/gui.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class Painter {
2020
this.facing = frame.facing;
2121
this.z = ZOOM_DOWN + frame.height * (ZOOM_UP - ZOOM_DOWN);
2222
this.opacity = frame.opacity;
23-
this.brushColor = frame.foreground;
23+
this.brushColor = frame.color;
2424
}
2525

2626
draw(ctx: CanvasRenderingContext2D) {

src/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,16 @@ function ensureRunning() {
407407

408408
const errMessage = /(.*) \((\d+):(\d+)\)\s*$/.exec(err.message);
409409
if (errMessage) {
410-
const [, message, line, ch] = errMessage;
411-
const startPos = CodeMirror.Pos(+line, +ch);
412-
const token = editor.getTokenAt(startPos, true);
413-
startPos.line--;
410+
const [, message, msgLine, msgCh] = errMessage;
411+
const line = +msgLine - 1;
412+
const ch = +msgCh;
413+
const token = editor.getLineTokens(line, true).find(token => token.start === ch);
414+
const startPos = CodeMirror.Pos(line, ch);
414415
const endPos = { ...startPos, ch: startPos.ch + token.string.length };
415-
markErrorPos(startPos, endPos, `${message} '${token.string}' (${line}:${ch})`);
416+
markErrorPos(startPos, endPos, `${message} '${token.string}' (${line+1}:${ch})`);
416417
} else {
417-
output.error(err);
418+
const message = err.message ?? err;
419+
output.error(message);
418420
}
419421

420422
throw err;

src/interpreter.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ export class Interpreter {
152152
get: fn(() => currentColor),
153153
set: fn((c: any) => {
154154
currentColor = String(c);
155+
this.animation = new Animation(0, (_, keyFrame: Frame) => {
156+
return keyFrame.with({ color: currentColor });
157+
});
155158
}),
156159
});
157160

0 commit comments

Comments
 (0)