Skip to content

Commit

Permalink
Use expanded Span throughout
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSouther committed Dec 18, 2023
1 parent 4c8bcdc commit ca3f1f5
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 199 deletions.
8 changes: 5 additions & 3 deletions components/src/stores/asm.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ class Translator {
for (const instruction of this.asm.instructions) {
if (
(instruction.type === "A" || instruction.type === "C") &&
instruction.loc != undefined
instruction.span != undefined
) {
this.lineNumbers[instruction.loc.line] = currentLine;
this.lineNumbers[instruction.span.line] = currentLine;
currentLine += 1;
}
}
Expand All @@ -95,7 +95,7 @@ class Translator {
this.current += 1;
const instruction = this.asm.instructions[this.current];
if (instruction.type === "A" || instruction.type === "C") {
highlightInfo.sourceHighlight = instruction.loc;
highlightInfo.sourceHighlight = instruction.span;
const result = translateInstruction(this.asm.instructions[this.current]);
if (result === undefined) {
return;
Expand All @@ -104,6 +104,7 @@ class Translator {
highlightInfo.resultHighlight = {
start: this.current * 17,
end: (this.current + 1) * 17,
line: -1,
};

if (highlightInfo.sourceHighlight) {
Expand Down Expand Up @@ -228,6 +229,7 @@ export function makeAsmStore(
state.resultHighlight = {
start: i * 17,
end: (i + 1) * 17,
line: -1,
};
return;
}
Expand Down
12 changes: 10 additions & 2 deletions components/src/stores/chip.store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ describe("ChipStore", () => {

it("starts the cursor on the first instruction", () => {
expect(state.store.state.files.tst).toBe(not.tst);
expect(state.store.state.controls.span).toEqual({ start: 0, end: 33 });
expect(state.store.state.controls.span).toEqual({
start: 0,
end: 33,
line: 1,
});
});

it("leaves the cursor on the final character", async () => {
Expand All @@ -174,7 +178,11 @@ describe("ChipStore", () => {
// Past the end of the test
await state.store.actions.stepTest();

expect(state.store.state.controls.span).toEqual({ start: 81, end: 82 });
expect(state.store.state.controls.span).toEqual({
start: 81,
end: 82,
line: 4,
});
});
});
});
1 change: 1 addition & 0 deletions components/src/stores/chip.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ export function makeChipStore(
state.controls.span = {
start: end - 1,
end,
line: state.files.tst.split("\n").length,
};
}
}
Expand Down
Loading

0 comments on commit ca3f1f5

Please sign in to comment.