fix(ui): resolve inconsistent Ctrl+O expansion and truncation detection

This commit is contained in:
Coco Sheng
2026-03-11 12:56:51 -04:00
parent 50384ab3c9
commit b95d43680a
4 changed files with 23 additions and 4 deletions
+2 -1
View File
@@ -1754,7 +1754,8 @@ Logging in with Google... Restarting Gemini CLI to continue.
if (!isAlternateBuffer) {
refreshStatic();
}
return true;
// Return false to allow other components (e.g. ToolConfirmationMessage) to also handle expansion.
return false;
} else if (
(keyMatchers[Command.FOCUS_SHELL_INPUT](key) ||
keyMatchers[Command.UNFOCUS_BACKGROUND_SHELL_LIST](key)) &&
@@ -176,7 +176,8 @@ export const ToolConfirmationMessage: React.FC<
callId,
expanded: !isMcpToolDetailsExpanded,
});
return true;
// Return false to let the global app container also expand its view.
return false;
}
if (keyMatchers[Command.ESCAPE](key)) {
handleConfirm(ToolConfirmationOutcome.Cancel);
@@ -6,7 +6,7 @@
import { render, renderWithProviders } from '../../../test-utils/render.js';
import { OverflowProvider } from '../../contexts/OverflowContext.js';
import { MaxSizedBox } from './MaxSizedBox.js';
import { MaxSizedBox, ceilHeight } from './MaxSizedBox.js';
import { MarkdownDisplay } from '../../utils/MarkdownDisplay.js';
import { Box, Text } from 'ink';
import { act } from 'react';
@@ -316,4 +316,17 @@ describe('<MaxSizedBox />', () => {
expect(lastFrame()).toMatchSnapshot();
unmount();
});
describe('ceilHeight', () => {
it('should round up fractional heights to next integer', () => {
expect(ceilHeight(2.1)).toBe(3);
expect(ceilHeight(2.9)).toBe(3);
expect(ceilHeight(2.0)).toBe(2);
expect(ceilHeight(0.1)).toBe(1);
});
it('should handle zero correctly', () => {
expect(ceilHeight(0)).toBe(0);
});
});
});
@@ -28,6 +28,9 @@ export interface MaxSizedBoxProps {
additionalHiddenLinesCount?: number;
}
/** Ensures that fractional heights are correctly identified as overflowing. */
export const ceilHeight = (height: number): number => Math.ceil(height);
/**
* A React component that constrains the size of its children and provides
* content-aware truncation when the content exceeds the specified `maxHeight`.
@@ -55,7 +58,8 @@ export const MaxSizedBox: React.FC<MaxSizedBoxProps> = ({
const observer = new ResizeObserver((entries) => {
const entry = entries[0];
if (entry) {
setContentHeight(Math.round(entry.contentRect.height));
// Use ceilHeight to ensure that fractional heights (e.g. from zooming) that exceed the limit are correctly identified as overflowing.
setContentHeight(ceilHeight(entry.contentRect.height));
}
});
observer.observe(node);