Skip to content

Commit 431cbe1

Browse files
authored
fix(ui): added a gutter width to the input prompt width calculation (google-gemini#26882)
1 parent 4f1567c commit 431cbe1

4 files changed

Lines changed: 69 additions & 1 deletion

packages/cli/src/ui/components/InputPrompt.test.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5332,6 +5332,34 @@ describe('InputPrompt', () => {
53325332
});
53335333
});
53345334
});
5335+
5336+
describe('terminal buffer rendering', () => {
5337+
it('does not clip the last char of a visual line whose width equals inputWidth', async () => {
5338+
const fullLine = '1234567890'; // 10 chars, exactly props.inputWidth
5339+
props.inputWidth = 10;
5340+
props.suggestionsWidth = 10;
5341+
vi.spyOn(props.config, 'getUseTerminalBuffer').mockReturnValue(true);
5342+
mockBuffer.text = fullLine;
5343+
mockBuffer.lines = [fullLine];
5344+
mockBuffer.allVisualLines = [fullLine];
5345+
mockBuffer.viewportVisualLines = [fullLine];
5346+
mockBuffer.visualToLogicalMap = [[0, 0]];
5347+
mockBuffer.visualToTransformedMap = [0];
5348+
mockBuffer.transformationsByLine = [[]];
5349+
mockBuffer.cursor = [0, fullLine.length];
5350+
mockBuffer.visualCursor = [0, fullLine.length];
5351+
5352+
const { lastFrame, unmount } = await renderWithProviders(
5353+
<TestInputPrompt {...props} />,
5354+
{ uiActions },
5355+
);
5356+
5357+
await waitFor(() => {
5358+
expect(clean(lastFrame())).toContain(fullLine);
5359+
});
5360+
unmount();
5361+
});
5362+
});
53355363
});
53365364

53375365
function clean(str: string | undefined): string {

packages/cli/src/ui/components/InputPrompt.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ import { useIsHelpDismissKey } from '../utils/shortcutsHelp.js';
9393
import { useRepeatedKeyPress } from '../hooks/useRepeatedKeyPress.js';
9494
import { useKeyMatchers } from '../hooks/useKeyMatchers.js';
9595

96+
const SCROLLBAR_GUTTER_WIDTH = 1;
97+
9698
/**
9799
* Returns if the terminal can be trusted to handle paste events atomically
98100
* rather than potentially sending multiple paste events separated by line
@@ -1868,7 +1870,7 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
18681870
? `line-${item.absoluteVisualIdx}`
18691871
: `ghost-${item.index}`
18701872
}
1871-
width={inputWidth}
1873+
width={inputWidth + SCROLLBAR_GUTTER_WIDTH}
18721874
backgroundColor={listBackgroundColor}
18731875
containerHeight={Math.min(
18741876
buffer.viewportHeight,
Loading

packages/cli/src/ui/components/__snapshots__/InputPrompt.test.tsx.snap

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ exports[`InputPrompt > Highlighting and Cursor Display > single-line scenarios >
6060
────────────────────────────────────────────────────────────────────────────────────────────────────"
6161
`;
6262

63+
exports[`InputPrompt > Highlighting and Cursor Display > single-line scenarios > should display cursor correctly 'at the end of the line' 2`] = `
64+
"────────────────────────────────────────────────────────────────────────────────────────────────────
65+
> hello
66+
────────────────────────────────────────────────────────────────────────────────────────────────────"
67+
`;
68+
6369
exports[`InputPrompt > Highlighting and Cursor Display > single-line scenarios > should display cursor correctly 'for multi-byte unicode characters' 1`] = `
6470
"────────────────────────────────────────────────────────────────────────────────────────────────────
6571
> hello 👍 world
@@ -168,6 +174,27 @@ exports[`InputPrompt > mouse interaction > should toggle paste expansion on doub
168174
"
169175
`;
170176

177+
exports[`InputPrompt > mouse interaction > should toggle paste expansion on double-click 4`] = `
178+
"▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
179+
> [Pasted Text: 10 lines]
180+
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
181+
"
182+
`;
183+
184+
exports[`InputPrompt > mouse interaction > should toggle paste expansion on double-click 5`] = `
185+
"▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
186+
> [Pasted Text: 10 lines]
187+
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
188+
"
189+
`;
190+
191+
exports[`InputPrompt > mouse interaction > should toggle paste expansion on double-click 6`] = `
192+
"▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
193+
> [Pasted Text: 10 lines]
194+
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
195+
"
196+
`;
197+
171198
exports[`InputPrompt > multiline rendering > should correctly render multiline input including blank lines 1`] = `
172199
"────────────────────────────────────────────────────────────────────────────────────────────────────
173200
> hello

0 commit comments

Comments
 (0)