Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/codeEditor/electron-browser/inputClipboardActions.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { KeybindingsRegistry } from '../../../../platform/keybinding/common/keybindingsRegistry.js';
7
import * as platform from '../../../../base/common/platform.js';
8
import { KeyCode, KeyMod } from '../../../../base/common/keyCodes.js';
9
import { getActiveWindow } from '../../../../base/browser/dom.js';
10
11
if (platform.isMacintosh) {
12
13
// On the mac, cmd+x, cmd+c and cmd+v do not result in cut / copy / paste
14
// We therefore add a basic keybinding rule that invokes document.execCommand
15
// This is to cover <input>s...
16
17
KeybindingsRegistry.registerCommandAndKeybindingRule({
18
id: 'execCut',
19
primary: KeyMod.CtrlCmd | KeyCode.KeyX,
20
handler: bindExecuteCommand('cut'),
21
weight: 0,
22
when: undefined,
23
});
24
KeybindingsRegistry.registerCommandAndKeybindingRule({
25
id: 'execCopy',
26
primary: KeyMod.CtrlCmd | KeyCode.KeyC,
27
handler: bindExecuteCommand('copy'),
28
weight: 0,
29
when: undefined,
30
});
31
KeybindingsRegistry.registerCommandAndKeybindingRule({
32
id: 'execPaste',
33
primary: KeyMod.CtrlCmd | KeyCode.KeyV,
34
handler: bindExecuteCommand('paste'),
35
weight: 0,
36
when: undefined,
37
});
38
39
function bindExecuteCommand(command: 'cut' | 'copy' | 'paste') {
40
return () => {
41
getActiveWindow().document.execCommand(command);
42
};
43
}
44
}
45
46