mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-06 03:10:42 -07:00
feat: replace large text pastes with [Pasted Text: X lines] placeholder (#16422)
This commit is contained in:
@@ -4,21 +4,28 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {
|
||||
type Transformation,
|
||||
PASTED_TEXT_PLACEHOLDER_REGEX,
|
||||
} from '../components/shared/text-buffer.js';
|
||||
import { LRUCache } from 'mnemonist';
|
||||
import type { Transformation } from '../components/shared/text-buffer.js';
|
||||
import { cpLen, cpSlice } from './textUtils.js';
|
||||
import { LRU_BUFFER_PERF_CACHE_LIMIT } from '../constants.js';
|
||||
|
||||
export type HighlightToken = {
|
||||
text: string;
|
||||
type: 'default' | 'command' | 'file';
|
||||
type: 'default' | 'command' | 'file' | 'paste';
|
||||
};
|
||||
|
||||
// Matches slash commands (e.g., /help) and @ references (files or MCP resource URIs).
|
||||
// Matches slash commands (e.g., /help), @ references (files or MCP resource URIs),
|
||||
// and large paste placeholders (e.g., [Pasted Text: 6 lines]).
|
||||
// The @ pattern uses a negated character class to support URIs like `@file:///example.txt`
|
||||
// which contain colons. It matches any character except delimiters: comma, whitespace,
|
||||
// semicolon, common punctuation, and brackets.
|
||||
const HIGHLIGHT_REGEX = /(^\/[a-zA-Z0-9_-]+|@(?:\\ |[^,\s;!?()[\]{}])+)/g;
|
||||
const HIGHLIGHT_REGEX = new RegExp(
|
||||
`(^/[a-zA-Z0-9_-]+|@(?:\\\\ |[^,\\s;!?()\\[\\]{}])+|${PASTED_TEXT_PLACEHOLDER_REGEX.source})`,
|
||||
'g',
|
||||
);
|
||||
|
||||
const highlightCache = new LRUCache<string, readonly HighlightToken[]>(
|
||||
LRU_BUFFER_PERF_CACHE_LIMIT,
|
||||
@@ -66,7 +73,11 @@ export function parseInputForHighlighting(
|
||||
tokens.push({ text: text.slice(last, matchIndex), type: 'default' });
|
||||
}
|
||||
|
||||
const type = fullMatch.startsWith('/') ? 'command' : 'file';
|
||||
const type = fullMatch.startsWith('/')
|
||||
? 'command'
|
||||
: fullMatch.startsWith('@')
|
||||
? 'file'
|
||||
: 'paste';
|
||||
if (type === 'command' && index !== 0) {
|
||||
tokens.push({ text: fullMatch, type: 'default' });
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user