mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
Fixes #82603: Remove SelectionClipboardController from web
This commit is contained in:
parent
da114f3625
commit
620a5e80a0
|
@ -325,6 +325,10 @@ export namespace EditorExtensionsRegistry {
|
|||
return EditorContributionRegistry.INSTANCE.getEditorContributions();
|
||||
}
|
||||
|
||||
export function getSomeEditorContributions(ids: string[]): IEditorContributionDescription[] {
|
||||
return EditorContributionRegistry.INSTANCE.getEditorContributions().filter(c => ids.indexOf(c.id) >= 0);
|
||||
}
|
||||
|
||||
export function getDiffEditorContributions(): IDiffEditorContributionDescription[] {
|
||||
return EditorContributionRegistry.INSTANCE.getDiffEditorContributions();
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import './accessibility/accessibility';
|
|||
import './diffEditorHelper';
|
||||
import './inspectKeybindings';
|
||||
import './largeFileOptimizations';
|
||||
import './selectionClipboard';
|
||||
import './inspectTMScopes/inspectTMScopes';
|
||||
import './toggleMinimap';
|
||||
import './toggleMultiCursorModifier';
|
||||
|
|
|
@ -3,93 +3,4 @@
|
|||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { RunOnceScheduler } from 'vs/base/common/async';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import * as platform from 'vs/base/common/platform';
|
||||
import { ICodeEditor, IEditorMouseEvent } from 'vs/editor/browser/editorBrowser';
|
||||
import { registerEditorContribution } from 'vs/editor/browser/editorExtensions';
|
||||
import { ConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions';
|
||||
import { ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { IEditorContribution } from 'vs/editor/common/editorCommon';
|
||||
import { EndOfLinePreference } from 'vs/editor/common/model';
|
||||
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
|
||||
|
||||
export class SelectionClipboard extends Disposable implements IEditorContribution {
|
||||
private static readonly SELECTION_LENGTH_LIMIT = 65536;
|
||||
public static readonly ID = 'editor.contrib.selectionClipboard';
|
||||
|
||||
constructor(editor: ICodeEditor, @IClipboardService clipboardService: IClipboardService) {
|
||||
super();
|
||||
|
||||
if (platform.isLinux) {
|
||||
let isEnabled = editor.getOption(EditorOption.selectionClipboard);
|
||||
|
||||
this._register(editor.onDidChangeConfiguration((e: ConfigurationChangedEvent) => {
|
||||
if (e.hasChanged(EditorOption.selectionClipboard)) {
|
||||
isEnabled = editor.getOption(EditorOption.selectionClipboard);
|
||||
}
|
||||
}));
|
||||
|
||||
this._register(editor.onMouseUp((e: IEditorMouseEvent) => {
|
||||
if (!isEnabled) {
|
||||
if (e.event.middleButton) {
|
||||
// try to stop the upcoming paste
|
||||
e.event.preventDefault();
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
let setSelectionToClipboard = this._register(new RunOnceScheduler(() => {
|
||||
if (!editor.hasModel()) {
|
||||
return;
|
||||
}
|
||||
let model = editor.getModel();
|
||||
let selections = editor.getSelections();
|
||||
selections = selections.slice(0);
|
||||
selections.sort(Range.compareRangesUsingStarts);
|
||||
|
||||
let resultLength = 0;
|
||||
for (const sel of selections) {
|
||||
if (sel.isEmpty()) {
|
||||
// Only write if all cursors have selection
|
||||
return;
|
||||
}
|
||||
resultLength += model.getValueLengthInRange(sel);
|
||||
}
|
||||
|
||||
if (resultLength > SelectionClipboard.SELECTION_LENGTH_LIMIT) {
|
||||
// This is a large selection!
|
||||
// => do not write it to the selection clipboard
|
||||
return;
|
||||
}
|
||||
|
||||
let result: string[] = [];
|
||||
for (const sel of selections) {
|
||||
result.push(model.getValueInRange(sel, EndOfLinePreference.TextDefined));
|
||||
}
|
||||
|
||||
let textToCopy = result.join(model.getEOL());
|
||||
clipboardService.writeText(textToCopy, 'selection');
|
||||
}, 100));
|
||||
|
||||
this._register(editor.onDidChangeCursorSelection((e: ICursorSelectionChangedEvent) => {
|
||||
if (!isEnabled) {
|
||||
return;
|
||||
}
|
||||
if (e.source === 'restoreState') {
|
||||
// do not set selection to clipboard if this selection change
|
||||
// was caused by restoring editors...
|
||||
return;
|
||||
}
|
||||
setSelectionToClipboard.schedule();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
registerEditorContribution(SelectionClipboard.ID, SelectionClipboard);
|
||||
export const SelectionClipboardContributionID = 'editor.contrib.selectionClipboard';
|
||||
|
|
|
@ -9,8 +9,9 @@ import { ContextMenuController } from 'vs/editor/contrib/contextmenu/contextmenu
|
|||
import { SnippetController2 } from 'vs/editor/contrib/snippet/snippetController2';
|
||||
import { SuggestController } from 'vs/editor/contrib/suggest/suggestController';
|
||||
import { MenuPreventer } from 'vs/workbench/contrib/codeEditor/browser/menuPreventer';
|
||||
import { SelectionClipboard } from 'vs/workbench/contrib/codeEditor/browser/selectionClipboard';
|
||||
import { SelectionClipboardContributionID } from 'vs/workbench/contrib/codeEditor/browser/selectionClipboard';
|
||||
import { TabCompletionController } from 'vs/workbench/contrib/snippets/browser/tabCompletion';
|
||||
import { EditorExtensionsRegistry } from 'vs/editor/browser/editorExtensions';
|
||||
|
||||
export function getSimpleEditorOptions(): IEditorOptions {
|
||||
return {
|
||||
|
@ -40,13 +41,13 @@ export function getSimpleEditorOptions(): IEditorOptions {
|
|||
export function getSimpleCodeEditorWidgetOptions(): ICodeEditorWidgetOptions {
|
||||
return {
|
||||
isSimpleWidget: true,
|
||||
contributions: [
|
||||
{ id: MenuPreventer.ID, ctor: MenuPreventer },
|
||||
{ id: SelectionClipboard.ID, ctor: SelectionClipboard },
|
||||
{ id: ContextMenuController.ID, ctor: ContextMenuController },
|
||||
{ id: SuggestController.ID, ctor: SuggestController },
|
||||
{ id: SnippetController2.ID, ctor: SnippetController2 },
|
||||
{ id: TabCompletionController.ID, ctor: TabCompletionController },
|
||||
]
|
||||
contributions: EditorExtensionsRegistry.getSomeEditorContributions([
|
||||
MenuPreventer.ID,
|
||||
SelectionClipboardContributionID,
|
||||
ContextMenuController.ID,
|
||||
SuggestController.ID,
|
||||
SnippetController2.ID,
|
||||
TabCompletionController.ID,
|
||||
])
|
||||
};
|
||||
}
|
||||
|
|
|
@ -31,7 +31,8 @@ import { IStyleOverrides, IThemable, attachStyler } from 'vs/platform/theme/comm
|
|||
import { IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
|
||||
import { MenuPreventer } from 'vs/workbench/contrib/codeEditor/browser/menuPreventer';
|
||||
import { getSimpleEditorOptions } from 'vs/workbench/contrib/codeEditor/browser/simpleEditorOptions';
|
||||
import { SelectionClipboard } from 'vs/workbench/contrib/codeEditor/browser/selectionClipboard';
|
||||
import { SelectionClipboardContributionID } from 'vs/workbench/contrib/codeEditor/browser/selectionClipboard';
|
||||
import { EditorExtensionsRegistry } from 'vs/editor/browser/editorExtensions';
|
||||
|
||||
interface SuggestResultsProvider {
|
||||
/**
|
||||
|
@ -130,13 +131,13 @@ export class SuggestEnabledInput extends Widget implements IThemable {
|
|||
this.inputWidget = instantiationService.createInstance(CodeEditorWidget, this.stylingContainer,
|
||||
editorOptions,
|
||||
{
|
||||
contributions: [
|
||||
{ id: SuggestController.ID, ctor: SuggestController },
|
||||
{ id: SnippetController2.ID, ctor: SnippetController2 },
|
||||
{ id: ContextMenuController.ID, ctor: ContextMenuController },
|
||||
{ id: MenuPreventer.ID, ctor: MenuPreventer },
|
||||
{ id: SelectionClipboard.ID, ctor: SelectionClipboard }
|
||||
],
|
||||
contributions: EditorExtensionsRegistry.getSomeEditorContributions([
|
||||
SuggestController.ID,
|
||||
SnippetController2.ID,
|
||||
ContextMenuController.ID,
|
||||
MenuPreventer.ID,
|
||||
SelectionClipboardContributionID,
|
||||
]),
|
||||
isSimpleWidget: true,
|
||||
});
|
||||
this._register(this.inputWidget);
|
||||
|
|
|
@ -4,3 +4,4 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import './sleepResumeRepaintMinimap';
|
||||
import './selectionClipboard';
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { RunOnceScheduler } from 'vs/base/common/async';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import * as platform from 'vs/base/common/platform';
|
||||
import { ICodeEditor, IEditorMouseEvent } from 'vs/editor/browser/editorBrowser';
|
||||
import { registerEditorContribution } from 'vs/editor/browser/editorExtensions';
|
||||
import { ConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions';
|
||||
import { ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { IEditorContribution } from 'vs/editor/common/editorCommon';
|
||||
import { EndOfLinePreference } from 'vs/editor/common/model';
|
||||
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
|
||||
import { SelectionClipboardContributionID } from 'vs/workbench/contrib/codeEditor/browser/selectionClipboard';
|
||||
|
||||
export class SelectionClipboard extends Disposable implements IEditorContribution {
|
||||
private static readonly SELECTION_LENGTH_LIMIT = 65536;
|
||||
|
||||
constructor(editor: ICodeEditor, @IClipboardService clipboardService: IClipboardService) {
|
||||
super();
|
||||
|
||||
if (platform.isLinux) {
|
||||
let isEnabled = editor.getOption(EditorOption.selectionClipboard);
|
||||
|
||||
this._register(editor.onDidChangeConfiguration((e: ConfigurationChangedEvent) => {
|
||||
if (e.hasChanged(EditorOption.selectionClipboard)) {
|
||||
isEnabled = editor.getOption(EditorOption.selectionClipboard);
|
||||
}
|
||||
}));
|
||||
|
||||
this._register(editor.onMouseUp((e: IEditorMouseEvent) => {
|
||||
if (!isEnabled) {
|
||||
if (e.event.middleButton) {
|
||||
// try to stop the upcoming paste
|
||||
e.event.preventDefault();
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
let setSelectionToClipboard = this._register(new RunOnceScheduler(() => {
|
||||
if (!editor.hasModel()) {
|
||||
return;
|
||||
}
|
||||
let model = editor.getModel();
|
||||
let selections = editor.getSelections();
|
||||
selections = selections.slice(0);
|
||||
selections.sort(Range.compareRangesUsingStarts);
|
||||
|
||||
let resultLength = 0;
|
||||
for (const sel of selections) {
|
||||
if (sel.isEmpty()) {
|
||||
// Only write if all cursors have selection
|
||||
return;
|
||||
}
|
||||
resultLength += model.getValueLengthInRange(sel);
|
||||
}
|
||||
|
||||
if (resultLength > SelectionClipboard.SELECTION_LENGTH_LIMIT) {
|
||||
// This is a large selection!
|
||||
// => do not write it to the selection clipboard
|
||||
return;
|
||||
}
|
||||
|
||||
let result: string[] = [];
|
||||
for (const sel of selections) {
|
||||
result.push(model.getValueInRange(sel, EndOfLinePreference.TextDefined));
|
||||
}
|
||||
|
||||
let textToCopy = result.join(model.getEOL());
|
||||
clipboardService.writeText(textToCopy, 'selection');
|
||||
}, 100));
|
||||
|
||||
this._register(editor.onDidChangeCursorSelection((e: ICursorSelectionChangedEvent) => {
|
||||
if (!isEnabled) {
|
||||
return;
|
||||
}
|
||||
if (e.source === 'restoreState') {
|
||||
// do not set selection to clipboard if this selection change
|
||||
// was caused by restoring editors...
|
||||
return;
|
||||
}
|
||||
setSelectionToClipboard.schedule();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
registerEditorContribution(SelectionClipboardContributionID, SelectionClipboard);
|
Loading…
Reference in a new issue