mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-13 15:40:57 -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:
@@ -4,6 +4,8 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { cpLen, cpSlice } from './textUtils.js';
|
||||
|
||||
export type HighlightToken = {
|
||||
text: string;
|
||||
type: 'default' | 'command' | 'file';
|
||||
@@ -63,3 +65,39 @@ export function parseInputForHighlighting(
|
||||
|
||||
return tokens;
|
||||
}
|
||||
|
||||
export function buildSegmentsForVisualSlice(
|
||||
tokens: readonly HighlightToken[],
|
||||
sliceStart: number,
|
||||
sliceEnd: number,
|
||||
): readonly HighlightToken[] {
|
||||
if (sliceStart >= sliceEnd) return [];
|
||||
|
||||
const segments: HighlightToken[] = [];
|
||||
let tokenCpStart = 0;
|
||||
|
||||
for (const token of tokens) {
|
||||
const tokenLen = cpLen(token.text);
|
||||
const tokenStart = tokenCpStart;
|
||||
const tokenEnd = tokenStart + tokenLen;
|
||||
|
||||
const overlapStart = Math.max(tokenStart, sliceStart);
|
||||
const overlapEnd = Math.min(tokenEnd, sliceEnd);
|
||||
if (overlapStart < overlapEnd) {
|
||||
const sliceStartInToken = overlapStart - tokenStart;
|
||||
const sliceEndInToken = overlapEnd - tokenStart;
|
||||
const rawSlice = cpSlice(token.text, sliceStartInToken, sliceEndInToken);
|
||||
|
||||
const last = segments[segments.length - 1];
|
||||
if (last && last.type === token.type) {
|
||||
last.text += rawSlice;
|
||||
} else {
|
||||
segments.push({ type: token.type, text: rawSlice });
|
||||
}
|
||||
}
|
||||
|
||||
tokenCpStart += tokenLen;
|
||||
}
|
||||
|
||||
return segments;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user