mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
fix(terminal): send the final size to a newly started PTY (#5473)
A new project's first terminal can end up with the wrong size. While the shell is starting, the terminal may resize, for example when the font finishes loading. That new size never reaches the shell. Full-screen programs such as vim then draw at the old width and the text looks broken. This fix sends the current size once the shell is ready. Co-authored-by: zhzhsx <1379025+zhzhsx@users.noreply.github.com>
This commit is contained in:
@@ -389,6 +389,58 @@ describe("terminal restart", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("terminal startup size", () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it("resizes a freshly spawned PTY to the grid reached while startup was pending", async () => {
|
||||
let release: ((value: { id: number; title: string }) => void) | undefined;
|
||||
ipc.commands.termSpawn.mockImplementationOnce(
|
||||
() =>
|
||||
new Promise<{ id: number; title: string }>((resolve) => {
|
||||
release = resolve;
|
||||
}),
|
||||
);
|
||||
const session = new TerminalSession({ key: "s-start-size", cwd: "/repo", onChange() {}, onFocus() {} });
|
||||
try {
|
||||
session.term.resize(80, 24);
|
||||
const starting = session.start();
|
||||
await vi.waitFor(() => expect(release).toBeTypeOf("function"));
|
||||
expect(ipc.commands.termSpawn).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ cols: 80, rows: 24 }),
|
||||
expect.anything(),
|
||||
);
|
||||
// Resize while startup is still pending.
|
||||
session.term.resize(100, 30);
|
||||
release!({ id: 12, title: "zsh" });
|
||||
await starting;
|
||||
expect(ipc.commands.termResize).toHaveBeenCalledWith(12, 100, 30);
|
||||
} finally {
|
||||
session.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
it("leaves the PTY alone when the grid did not change during startup", async () => {
|
||||
let release: ((value: { id: number; title: string }) => void) | undefined;
|
||||
ipc.commands.termSpawn.mockImplementationOnce(
|
||||
() =>
|
||||
new Promise<{ id: number; title: string }>((resolve) => {
|
||||
release = resolve;
|
||||
}),
|
||||
);
|
||||
const session = new TerminalSession({ key: "s-start-same", cwd: "/repo", onChange() {}, onFocus() {} });
|
||||
try {
|
||||
session.term.resize(80, 24);
|
||||
const starting = session.start();
|
||||
await vi.waitFor(() => expect(release).toBeTypeOf("function"));
|
||||
release!({ id: 13, title: "zsh" });
|
||||
await starting;
|
||||
expect(ipc.commands.termResize).not.toHaveBeenCalled();
|
||||
} finally {
|
||||
session.dispose();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("terminal open", () => {
|
||||
afterEach(() => vi.useRealTimers());
|
||||
|
||||
|
||||
@@ -858,6 +858,8 @@ export class TerminalSession {
|
||||
}
|
||||
this.ptyId = info.id;
|
||||
this.update({ status: "running", title: info.title || "Local" });
|
||||
// Send the new size if it changed while the program was starting.
|
||||
if (this.term.cols !== cols || this.term.rows !== rows) this.resizePty(this.term.cols, this.term.rows);
|
||||
this.flushPendingInput();
|
||||
} catch (e) {
|
||||
this.pendingInput = "";
|
||||
|
||||
Reference in New Issue
Block a user