mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-13 07:30:52 -07:00
fix: InputPrompt wrapped lines maintain highlighting, increase responsiveness in narrow cases (#7656)
Co-authored-by: Jacob Richman <jacob314@gmail.com> Co-authored-by: Arya Gummadi <aryagummadi@google.com>
This commit is contained in:
@@ -1568,7 +1568,7 @@ export function useTextBuffer({
|
||||
[visualLayout, cursorRow, cursorCol],
|
||||
);
|
||||
|
||||
const { visualLines } = visualLayout;
|
||||
const { visualLines, visualToLogicalMap } = visualLayout;
|
||||
|
||||
const [visualScrollRow, setVisualScrollRow] = useState<number>(0);
|
||||
|
||||
@@ -1588,6 +1588,8 @@ export function useTextBuffer({
|
||||
// Update visual scroll (vertical)
|
||||
useEffect(() => {
|
||||
const { height } = viewport;
|
||||
const totalVisualLines = visualLines.length;
|
||||
const maxScrollStart = Math.max(0, totalVisualLines - height);
|
||||
let newVisualScrollRow = visualScrollRow;
|
||||
|
||||
if (visualCursor[0] < visualScrollRow) {
|
||||
@@ -1595,10 +1597,15 @@ export function useTextBuffer({
|
||||
} else if (visualCursor[0] >= visualScrollRow + height) {
|
||||
newVisualScrollRow = visualCursor[0] - height + 1;
|
||||
}
|
||||
|
||||
// When the number of visual lines shrinks (e.g., after widening the viewport),
|
||||
// ensure scroll never starts beyond the last valid start so we can render a full window.
|
||||
newVisualScrollRow = clamp(newVisualScrollRow, 0, maxScrollStart);
|
||||
|
||||
if (newVisualScrollRow !== visualScrollRow) {
|
||||
setVisualScrollRow(newVisualScrollRow);
|
||||
}
|
||||
}, [visualCursor, visualScrollRow, viewport]);
|
||||
}, [visualCursor, visualScrollRow, viewport, visualLines.length]);
|
||||
|
||||
const insert = useCallback(
|
||||
(ch: string, { paste = false }: { paste?: boolean } = {}): void => {
|
||||
@@ -1988,6 +1995,7 @@ export function useTextBuffer({
|
||||
viewportVisualLines: renderedVisualLines,
|
||||
visualCursor,
|
||||
visualScrollRow,
|
||||
visualToLogicalMap,
|
||||
|
||||
setText,
|
||||
insert,
|
||||
@@ -2063,6 +2071,12 @@ export interface TextBuffer {
|
||||
viewportVisualLines: string[]; // The subset of visual lines to be rendered based on visualScrollRow and viewport.height
|
||||
visualCursor: [number, number]; // Visual cursor [row, col] relative to the start of all visualLines
|
||||
visualScrollRow: number; // Scroll position for visual lines (index of the first visible visual line)
|
||||
/**
|
||||
* For each visual line (by absolute index in allVisualLines) provides a tuple
|
||||
* [logicalLineIndex, startColInLogical] that maps where that visual line
|
||||
* begins within the logical buffer. Indices are code-point based.
|
||||
*/
|
||||
visualToLogicalMap: Array<[number, number]>;
|
||||
|
||||
// Actions
|
||||
|
||||
|
||||
Reference in New Issue
Block a user