Skip to content

Commit f0b8eb1

Browse files
committed
🐛 Draw a row as its own stretches only where the frame holds it whole
The engine wraps each text operation on its own, and a row is one cell tall: several stretches whose total is wider than the element each show their own first line and leave the cells their remainder went to blank. A 400-column generated tag in a 118-column drawer came out with its quoted values missing — found by capturing the gallery, which the focused tests could not reach because every example in them fits. A row carries its stretches only when the element it was measured in holds them whole, read off the constraint the element was opened with. A row the engine must wrap is drawn as the one thing it is, which is the reading this screen has always shown. The regression commits a tag far wider than any supported drawer and holds every written cell to being the next character of the source.
1 parent 56afe3a commit f0b8eb1

2 files changed

Lines changed: 73 additions & 1 deletion

File tree

‎packages/cli/src/repl/layout.ts‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,14 +778,27 @@ function decorated(box: ReplBox): ReplBoxProps {
778778
* flow, so what a reader sees is still one row of exactly the measured width —
779779
* while a child per token would be a box, a bound and a pointer target for every
780780
* delimiter on the screen.
781+
*
782+
* Only for a row the element can hold. The engine wraps each text operation it
783+
* is given **on its own**, and a row is one cell tall: several operations whose
784+
* total is wider than the element each show their own first line and leave the
785+
* cells their remainder went to blank — measured, a 400-column generated tag in
786+
* a 118-column drawer came out with its quoted values missing. One operation
787+
* wraps once, which is the reading this screen has always shown, so a row that
788+
* does not fit is drawn as the one thing it is.
781789
*/
782790
function written(content: string, box: ReplBox, focused: boolean): Op[] {
783791
const style = box.style;
784792
if (style === undefined) {
785793
return [text(content)];
786794
}
787795
const { runs } = box;
788-
if (runs === undefined || runs.length === 0 || runText(runs) !== content) {
796+
if (
797+
runs === undefined ||
798+
runs.length === 0 ||
799+
runText(runs) !== content ||
800+
!holds(box.props, content)
801+
) {
789802
const { colour, attrs } = textStyleOf(style, focused);
790803
return [drawn(content, colour, attrs)];
791804
}
@@ -795,6 +808,24 @@ function written(content: string, box: ReplBox, focused: boolean): Op[] {
795808
});
796809
}
797810

811+
/**
812+
* Whether this element holds this text without the engine wrapping it.
813+
*
814+
* Read off the constraint the element was opened with rather than worked out
815+
* again: a box stated at a measured width says how much room its text has, and
816+
* a box that sizes itself to its content always has enough.
817+
*/
818+
function holds(props: ReplBoxProps, content: string): boolean {
819+
const width = props.layout?.width;
820+
if (width === undefined) {
821+
return false;
822+
}
823+
if (width.type === "fit") {
824+
return true;
825+
}
826+
return width.type === "fixed" && content.length <= width.value;
827+
}
828+
798829
function drawn(content: string, colour: number, attrs: number): Op {
799830
return text(content, { color: terminalColour(colour), ...(attrs === 0 ? {} : { attrs }) });
800831
}

‎packages/cli/tests/repl-presentation-style.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,3 +1880,44 @@ describe("REPL presentation: decoration the frame measured", () => {
18801880
expect(observed.keys).toContain("drawer:close");
18811881
});
18821882
});
1883+
1884+
describe("REPL presentation: a row the frame cannot hold whole", () => {
1885+
beforeAll(() => useTempFileCompiler());
1886+
1887+
it("P1-T1: a source row wider than its drawer keeps every character it shows", function* () {
1888+
const model = yield* settledAndFailed();
1889+
// One tag far wider than any drawer at any supported size, so the engine
1890+
// has to wrap it. Drawn as several stretches it would wrap each of them on
1891+
// its own and leave the cells their remainders went to blank.
1892+
const long =
1893+
'<Elicit as="answers" schema={schema}>' +
1894+
"Enter the project details, at length, so that this one line is wider ".repeat(4) +
1895+
"</Elicit>";
1896+
const question = yield* askingWith(DETAILS_SCHEMA, long);
1897+
const presenter = yield* usePresenter(WIDE);
1898+
const observed = yield* presenter.commit(
1899+
reading(answering(stateWith({}), {}), model, asking(question), WIDE),
1900+
);
1901+
const { grid } = presenter;
1902+
1903+
const row = placed(observed, "drawer:message:0");
1904+
const shown = textOf(grid, row);
1905+
// Whatever the row shows is a prefix of the line it was given, with no gap
1906+
// where a stretch wrapped away: every written cell is the next character of
1907+
// the source, in order.
1908+
const written = shown.replace(/\s+$/, "");
1909+
expect(written.length).toBeGreaterThan(40);
1910+
expect(long.startsWith(written)).toBe(true);
1911+
expect(written).not.toContain(" ");
1912+
1913+
// And a row the drawer does hold is still read as the thing it is, so the
1914+
// bound is on the row that overflows rather than on the reading.
1915+
const short = yield* askingWith(DETAILS_SCHEMA, SOURCE_EXAMPLE.join("\n"));
1916+
const fitted = yield* presenter.commit(
1917+
reading(answering(stateWith({}), {}), model, asking(short), WIDE),
1918+
);
1919+
expect(inkOfSpan(grid, placed(fitted, "drawer:message:1"), "Elicit").foreground).toBe(
1920+
REPL_PALETTE.focus,
1921+
);
1922+
});
1923+
});

0 commit comments

Comments
 (0)