Compare commits

..
Author SHA1 Message Date
paseo-bot[bot] eccd3337d7 fix(app): restore the native terminal cursor beside the prompt
Measure the font sample outside the grid whose width is derived from those metrics. On cold Android startup the one-column grid wrapped the sample, temporarily shrinking the emulator and clamping the restored cursor before the final layout.
2026-10-24 18:32:46 +00:00
2 changed files with 58 additions and 3 deletions
@@ -0,0 +1,54 @@
import React, { act } from "react";
import { createRoot } from "react-dom/client";
import { expect, test } from "vitest";
import { TerminalGridView } from "./terminal-grid-view.native";
import type { TerminalViewportState } from "./headless-terminal-state";
import type { TerminalGridCellMetrics } from "./terminal-grid-metrics";
test("measures a single font cell before the terminal has its viewport columns", async () => {
const container = document.createElement("div");
container.style.cssText = "width: 400px; height: 700px; display: flex";
document.body.appendChild(container);
const root = createRoot(container);
const measurements: TerminalGridCellMetrics[] = [];
const state: TerminalViewportState = {
rows: 1,
cols: 1,
firstRow: 0,
oldestRow: 0,
newestRow: 0,
grid: [[{ char: " " }]],
cursor: { row: 0, col: 0 },
};
const style = { flex: 1 };
const recordMeasurement = (metrics: TerminalGridCellMetrics) => measurements.push(metrics);
try {
act(() =>
root.render(
React.createElement(TerminalGridView, {
state,
fontSize: 12,
style,
onCellMetricsChange: recordMeasurement,
}),
),
);
await expect.poll(() => measurements.length).toBeGreaterThan(0);
const sample = [...container.querySelectorAll("div")].find(
(element) => element.textContent === "mmmmmmmmmm" && element.childElementCount === 0,
);
expect(sample).toBeDefined();
// Native Text wraps to its containing block. Font measurement must fit even
// when the terminal starts with one column, before layout determines its size.
expect(sample!.parentElement!.getBoundingClientRect().width).toBeGreaterThanOrEqual(
sample!.getBoundingClientRect().width,
);
// The first measurement is used to size the emulator before restore data arrives.
// A wrapped ten-character sample reports a fraction of a cell and multiple lines.
expect(measurements[0].cellWidth).toBeGreaterThan(5);
expect(measurements[0].cellHeight).toBeLessThan(24);
} finally {
act(() => root.unmount());
container.remove();
}
});
@@ -407,10 +407,11 @@ export function TerminalGridView({
return (
<View onLayout={handleContainerLayout} pointerEvents="none" style={containerStyle}>
{/* Measure against the viewport, independently of the grid width derived from these metrics. */}
<Text onLayout={handleMeasure} pointerEvents="none" style={measureStyle}>
{MEASURE_TEXT}
</Text>
<View style={gridStyle}>
<Text onLayout={handleMeasure} pointerEvents="none" style={measureStyle}>
{MEASURE_TEXT}
</Text>
{rows.map((row) => (
<MemoTerminalGridRow
key={row.index}