Skip to content

Commit 286a883

Browse files
CSE Machine: Display implicit block for program environment in the Control (#2774)
* Add extra {} when the control item is of type Program * Format files properly and remove unnecessary lines
1 parent 7011a41 commit 286a883

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/features/envVisualizer/EnvVisualizerUtils.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,23 @@ export function getControlItemComponent(
413413
: index === Layout.control.size() - 1;
414414
if (!isInstr(controlItem)) {
415415
switch (controlItem.type) {
416+
case 'Program':
417+
// If the control item is the whole program
418+
// add {} to represent the implicit block
419+
const originalText = astToString(controlItem)
420+
.trim()
421+
.split('\n')
422+
.map(line => `\t\t${line}`)
423+
.join('\n');
424+
const textP = `{\n${originalText}\n}`;
425+
return new ControlItemComponent(
426+
textP,
427+
textP,
428+
stackHeight,
429+
highlightOnHover,
430+
unhighlightOnHover,
431+
topItem
432+
);
416433
case 'Literal':
417434
const textL =
418435
typeof controlItem.value === 'string' ? `"${controlItem.value}"` : controlItem.value;

src/features/envVisualizer/compactComponents/Text.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ export class Text extends Visible implements IHoverable {
5252
? JSON.stringify(data) || String(data)
5353
: String(data);
5454
this._height = fontSize;
55-
5655
const widthOf = (s: string) => getTextWidth(s, `${fontStyle} ${fontSize}px ${fontFamily}`);
5756
if (widthOf(this.partialStr) > maxWidth) {
5857
let truncatedText = CompactConfig.Ellipsis.toString();

0 commit comments

Comments
 (0)