Skip to content

Commit 2d1e215

Browse files
authored
Enable Shift-Insert to paste primary clipboard on Linux, fixes… (microsoft#63374)
Enable Shift-Insert to paste primary clipboard on Linux, fixes microsoft#36170.
2 parents 3140b9c + a4a3e90 commit 2d1e215

1 file changed

Lines changed: 43 additions & 2 deletions

File tree

src/vs/workbench/contrib/codeEditor/electron-browser/selectionClipboard.ts

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,27 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import * as nls from 'vs/nls';
67
import { RunOnceScheduler } from 'vs/base/common/async';
78
import { Disposable } from 'vs/base/common/lifecycle';
89
import * as platform from 'vs/base/common/platform';
910
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
10-
import { registerEditorContribution } from 'vs/editor/browser/editorExtensions';
11+
import { registerEditorContribution, EditorAction, ServicesAccessor, registerEditorAction } from 'vs/editor/browser/editorExtensions';
1112
import { ConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions';
1213
import { ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
1314
import { Range } from 'vs/editor/common/core/range';
14-
import { IEditorContribution } from 'vs/editor/common/editorCommon';
15+
import { IEditorContribution, Handler } from 'vs/editor/common/editorCommon';
1516
import { EndOfLinePreference } from 'vs/editor/common/model';
1617
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
1718
import { SelectionClipboardContributionID } from 'vs/workbench/contrib/codeEditor/browser/selectionClipboard';
1819
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
1920
import { Registry } from 'vs/platform/registry/common/platform';
2021
import { Extensions as WorkbenchExtensions, IWorkbenchContribution, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';
2122
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
23+
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
24+
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
25+
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
26+
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
2227

2328
export class SelectionClipboard extends Disposable implements IEditorContribution {
2429
private static readonly SELECTION_LENGTH_LIMIT = 65536;
@@ -107,5 +112,41 @@ class SelectionClipboardPastePreventer implements IWorkbenchContribution {
107112
}
108113
}
109114

115+
class PasteSelectionClipboardAction extends EditorAction {
116+
117+
constructor() {
118+
super({
119+
id: 'editor.action.selectionClipboardPaste',
120+
label: nls.localize('actions.pasteSelectionClipboard', "Paste Selection Clipboard"),
121+
alias: 'Paste Selection Clipboard',
122+
precondition: EditorContextKeys.writable,
123+
kbOpts: {
124+
kbExpr: ContextKeyExpr.and(
125+
EditorContextKeys.editorTextFocus,
126+
ContextKeyExpr.has('config.editor.selectionClipboard')
127+
),
128+
primary: KeyMod.Shift | KeyCode.Insert,
129+
weight: KeybindingWeight.EditorContrib
130+
}
131+
});
132+
}
133+
134+
public async run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): Promise<void> {
135+
const clipboardService = accessor.get(IClipboardService);
136+
137+
// read selection clipboard
138+
const text = await clipboardService.readText('selection');
139+
140+
editor.trigger('keyboard', Handler.Paste, {
141+
text: text,
142+
pasteOnNewLine: false,
143+
multicursorText: null
144+
});
145+
}
146+
}
147+
110148
registerEditorContribution(SelectionClipboardContributionID, SelectionClipboard);
111149
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(SelectionClipboardPastePreventer, LifecyclePhase.Ready);
150+
if (platform.isLinux) {
151+
registerEditorAction(PasteSelectionClipboardAction);
152+
}

0 commit comments

Comments
 (0)