Skip to content

Commit e5f1ac5

Browse files
authored
fix: terminal shortcut kill process in windows (#3100)
* fix: fix terminal ctrl+c shortcut can not kill process in windows * fix: fix terminal ctrl+c shortcut can not kill process in windows
1 parent 3ddb9aa commit e5f1ac5

5 files changed

Lines changed: 30 additions & 0 deletions

File tree

packages/core-browser/src/common/common.command.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,12 @@ export namespace TERMINAL_COMMANDS {
967967
label: '%terminal.toggleTerminal%',
968968
category: CATEGORY,
969969
};
970+
971+
export const KILL_PROCESS = {
972+
id: 'terminal.killProcess',
973+
label: '%terminal.killProcess%',
974+
category: CATEGORY,
975+
};
970976
}
971977

972978
export namespace LAYOUT_COMMANDS {

packages/i18n/src/common/en-US.lang.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,7 @@ export const localizationBundle = {
10321032
'terminal.openFolder': 'Open folder in new window',
10331033
'terminal.relaunch': 'Relaunch Terminal',
10341034
'terminal.toggleTerminal': 'Toggle Terminal',
1035+
'terminal.killProcess': 'Kill Process',
10351036

10361037
'terminal.focusNext.inTerminalGroup': 'Terminal: Focus Next Terminal in Terminal Group',
10371038
'terminal.focusPrevious.inTerminalGroup': 'Terminal: Focus Previous Terminal in Terminal Group',

packages/i18n/src/common/zh-CN.lang.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,7 @@ export const localizationBundle = {
705705
'terminal.focusFolder': '聚焦资源管理器中的文件夹',
706706
'terminal.openFolder': '在新窗口中打开文件夹',
707707
'terminal.toggleTerminal': '切换终端面板',
708+
'terminal.killProcess': '结束进程',
708709

709710
'view.command.show': '打开 {0}',
710711

packages/terminal-next/src/browser/contribution/terminal.command.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,23 @@ export class TerminalCommandContribution implements CommandContribution {
331331
client?.focus();
332332
},
333333
});
334+
335+
registry.registerCommand(TERMINAL_COMMANDS.KILL_PROCESS, {
336+
execute: async () => {
337+
const current = this.view.currentWidgetId;
338+
const client = this.terminalController.findClientFromWidgetId(current);
339+
if (client) {
340+
const select = client.getSelection();
341+
if (select && select.length > 0) {
342+
// 有选择内容则复制到剪贴板
343+
await this.clipboardService.writeText(client.getSelection());
344+
} else {
345+
// 没有选择内容则执行结束进程命令
346+
await this.terminalApi.sendText(current, '\x03');
347+
}
348+
}
349+
},
350+
});
334351
}
335352

336353
private getNextOrPrevTerminalClient(kind: 'next' | 'prev'): ITerminalClient | undefined {

packages/terminal-next/src/browser/contribution/terminal.keybinding.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ export class TerminalKeybindingContribution implements KeybindingContribution {
2727
// http 协议无法访问 navigator.clipboard,使用 xterm 原生快捷键
2828
when: RawContextKey.and(IsTerminalFocused.raw, 'locationProtocol != http'),
2929
});
30+
registry.registerKeybinding({
31+
command: TERMINAL_COMMANDS.KILL_PROCESS.id,
32+
keybinding: 'ctrlcmd+c',
33+
when: RawContextKey.and(IsTerminalFocused.raw, 'locationProtocol != http', 'isWindows'),
34+
});
3035
registry.registerKeybinding({
3136
command: TERMINAL_COMMANDS.PASTE.id,
3237
keybinding: isWindows ? 'ctrlcmd+shift+v' : 'ctrlcmd+v',

0 commit comments

Comments
 (0)