|
3 | 3 | * Licensed under the MIT License. See License.txt in the project root for license information. |
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
| 6 | +import * as nls from 'vs/nls'; |
6 | 7 | import { RunOnceScheduler } from 'vs/base/common/async'; |
7 | 8 | import { Disposable } from 'vs/base/common/lifecycle'; |
8 | 9 | import * as platform from 'vs/base/common/platform'; |
9 | 10 | 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'; |
11 | 12 | import { ConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; |
12 | 13 | import { ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents'; |
13 | 14 | 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'; |
15 | 16 | import { EndOfLinePreference } from 'vs/editor/common/model'; |
16 | 17 | import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; |
17 | 18 | import { SelectionClipboardContributionID } from 'vs/workbench/contrib/codeEditor/browser/selectionClipboard'; |
18 | 19 | import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle'; |
19 | 20 | import { Registry } from 'vs/platform/registry/common/platform'; |
20 | 21 | import { Extensions as WorkbenchExtensions, IWorkbenchContribution, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions'; |
21 | 22 | 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'; |
22 | 27 |
|
23 | 28 | export class SelectionClipboard extends Disposable implements IEditorContribution { |
24 | 29 | private static readonly SELECTION_LENGTH_LIMIT = 65536; |
@@ -107,5 +112,41 @@ class SelectionClipboardPastePreventer implements IWorkbenchContribution { |
107 | 112 | } |
108 | 113 | } |
109 | 114 |
|
| 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 | + |
110 | 148 | registerEditorContribution(SelectionClipboardContributionID, SelectionClipboard); |
111 | 149 | Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(SelectionClipboardPastePreventer, LifecyclePhase.Ready); |
| 150 | +if (platform.isLinux) { |
| 151 | + registerEditorAction(PasteSelectionClipboardAction); |
| 152 | +} |
0 commit comments