Files
openidea/src/platform/consoleColumns.test.ts
T
l0ng-ai 65e0feb98f fix(console): keep the scroll width of long output fixed (#2983)
Console rows are virtualized and absolutely placed, and such rows widen the
scroll area only while they are mounted. Scrolling a long line out of the
rendered range removed the horizontal scrollbar, and where scrollbars take
layout space (Windows) the taller viewport moved the range back, so the end
of a finished run flickered and its scrollbar jumped.

The widest line, measured incrementally in monospace columns (tabs to their
stop, CJK and emoji as two), now sets the content's minimum width. The same
applies to the Build and Debug consoles, which place their rows the same way.

Fixes #2933
2026-11-12 22:50:59 +08:00

32 lines
1.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { textColumns, WidestColumns } from "./consoleColumns";
describe("console columns", () => {
it("counts tabs to the next stop and wide characters twice", () => {
expect(textColumns("abc", 4)).toBe(3);
expect(textColumns("a\tb", 4)).toBe(5);
expect(textColumns("\t\t", 4)).toBe(8);
expect(textColumns("中文ok", 4)).toBe(6);
expect(textColumns("😀", 4)).toBe(2);
expect(textColumns("long line\nshort\n", 4)).toBe(9);
});
it("measures only new lines and the growing last one", () => {
const widest = new WidestColumns();
const lines = [{ text: "12345" }, { text: "12" }];
expect(widest.measure(lines)).toBe(5);
lines[1]!.text = "1234567";
expect(widest.measure(lines)).toBe(7);
// Dropping lines from the front keeps the width.
lines.splice(0, 1);
lines.push({ text: "1" });
expect(widest.measure(lines)).toBe(7);
// A new array of the same line objects (an immutable append) continues from the last one.
const next = [...lines, { text: "123456789" }];
expect(widest.measure(next)).toBe(9);
// A cleared console starts over.
expect(widest.measure([])).toBe(0);
expect(widest.measure([{ text: "abc" }])).toBe(3);
});
});