Preserve tabs on paste (#12735)

This commit is contained in:
Adib234
2025-11-10 07:37:43 -08:00
committed by GitHub
parent 4ab94dec5e
commit 331dbd5638
2 changed files with 10 additions and 3 deletions

View File

@@ -9,9 +9,15 @@ import type {
ToolCallConfirmationDetails,
ToolEditConfirmationDetails,
} from '@google/gemini-cli-core';
import { escapeAnsiCtrlCodes } from './textUtils.js';
import { escapeAnsiCtrlCodes, stripUnsafeCharacters } from './textUtils.js';
describe('textUtils', () => {
describe('stripUnsafeCharacters', () => {
it('should not strip tab characters', () => {
const input = 'hello world';
expect(stripUnsafeCharacters(input)).toBe('hello world');
});
});
describe('escapeAnsiCtrlCodes', () => {
describe('escapeAnsiCtrlCodes string case study', () => {
it('should replace ANSI escape codes with a visible representation', () => {

View File

@@ -89,6 +89,7 @@ export function cpSlice(str: string, start: number, end?: number): string {
* - All printable Unicode including emojis
* - DEL (0x7F) - handled functionally by applyOperations, not a display issue
* - CR/LF (0x0D/0x0A) - needed for line breaks
* - TAB (0x09) - preserve tabs
*/
export function stripUnsafeCharacters(str: string): string {
const strippedAnsi = stripAnsi(str);
@@ -99,8 +100,8 @@ export function stripUnsafeCharacters(str: string): string {
const code = char.codePointAt(0);
if (code === undefined) return false;
// Preserve CR/LF for line handling
if (code === 0x0a || code === 0x0d) return true;
// Preserve CR/LF/TAB for line handling
if (code === 0x0a || code === 0x0d || code === 0x09) return true;
// Remove C0 control chars (except CR/LF) that can break display
// Examples: BELL(0x07) makes noise, BS(0x08) moves cursor, VT(0x0B), FF(0x0C)