Skip to content

Commit 0bf775f

Browse files
authored
Restore bracketed paste mode after external editor exit (#13606)
1 parent 3e10bed commit 0bf775f

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

packages/cli/src/gemini.test.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
6262
write: vi.fn(),
6363
},
6464
})),
65+
enableMouseEvents: vi.fn(),
66+
disableMouseEvents: vi.fn(),
67+
enterAlternateScreen: vi.fn(),
68+
disableLineWrapping: vi.fn(),
6569
};
6670
});
6771

packages/cli/src/ui/AppContainer.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ import { isWorkspaceTrusted } from '../config/trustedFolders.js';
116116
import { useAlternateBuffer } from './hooks/useAlternateBuffer.js';
117117
import { useSettings } from './contexts/SettingsContext.js';
118118
import { enableSupportedProtocol } from './utils/kittyProtocolDetector.js';
119+
import { enableBracketedPaste } from './utils/bracketedPaste.js';
119120

120121
const WARNING_PROMPT_DURATION_MS = 1000;
121122
const QUEUE_ERROR_DISPLAY_DURATION_MS = 3000;
@@ -387,6 +388,7 @@ export const AppContainer = (props: AppContainerProps) => {
387388
disableLineWrapping();
388389
app.rerender();
389390
}
391+
enableBracketedPaste();
390392
enableSupportedProtocol();
391393
refreshStatic();
392394
}, [refreshStatic, isAlternateBuffer, app, config]);

packages/cli/src/ui/hooks/useBracketedPaste.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
*/
66

77
import { useEffect } from 'react';
8-
import { writeToStdout } from '@google/gemini-cli-core';
9-
10-
const ENABLE_BRACKETED_PASTE = '\x1b[?2004h';
11-
const DISABLE_BRACKETED_PASTE = '\x1b[?2004l';
8+
import {
9+
disableBracketedPaste,
10+
enableBracketedPaste,
11+
} from '../utils/bracketedPaste.js';
1212

1313
/**
1414
* Enables and disables bracketed paste mode in the terminal.
@@ -18,11 +18,11 @@ const DISABLE_BRACKETED_PASTE = '\x1b[?2004l';
1818
*/
1919
export const useBracketedPaste = () => {
2020
const cleanup = () => {
21-
writeToStdout(DISABLE_BRACKETED_PASTE);
21+
disableBracketedPaste();
2222
};
2323

2424
useEffect(() => {
25-
writeToStdout(ENABLE_BRACKETED_PASTE);
25+
enableBracketedPaste();
2626

2727
process.on('exit', cleanup);
2828
process.on('SIGINT', cleanup);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
import { writeToStdout } from '@google/gemini-cli-core';
8+
9+
const ENABLE_BRACKETED_PASTE = '\x1b[?2004h';
10+
const DISABLE_BRACKETED_PASTE = '\x1b[?2004l';
11+
12+
export const enableBracketedPaste = () => {
13+
writeToStdout(ENABLE_BRACKETED_PASTE);
14+
};
15+
16+
export const disableBracketedPaste = () => {
17+
writeToStdout(DISABLE_BRACKETED_PASTE);
18+
};

0 commit comments

Comments
 (0)