Skip to content

Commit 249357b

Browse files
committed
Dynamically import addon-clipboard
1 parent 30e7857 commit 249357b

File tree

2 files changed

+24
-37
lines changed

2 files changed

+24
-37
lines changed

src/vs/workbench/contrib/terminal/browser/xterm/vscodeClipboardAddon.ts

-31
This file was deleted.

src/vs/workbench/contrib/terminal/browser/xterm/xtermTerminal.ts

+24-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { Unicode11Addon as Unicode11AddonType } from '@xterm/addon-unicode1
99
import type { WebglAddon as WebglAddonType } from '@xterm/addon-webgl';
1010
import type { SerializeAddon as SerializeAddonType } from '@xterm/addon-serialize';
1111
import type { ImageAddon as ImageAddonType } from '@xterm/addon-image';
12-
import type { ClipboardAddon as ClipboardAddonType } from '@xterm/addon-clipboard';
12+
import type { ClipboardAddon as ClipboardAddonType, ClipboardSelectionType } from '@xterm/addon-clipboard';
1313
import * as dom from 'vs/base/browser/dom';
1414
import { IXtermCore } from 'vs/workbench/contrib/terminal/browser/xterm-private';
1515
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
@@ -40,12 +40,12 @@ import { MouseWheelClassifier } from 'vs/base/browser/ui/scrollbar/scrollableEle
4040
import { IMouseWheelEvent, StandardWheelEvent } from 'vs/base/browser/mouseEvent';
4141
import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
4242
import { AccessibilitySignal, IAccessibilitySignalService } from 'vs/platform/accessibilitySignal/browser/accessibilitySignalService';
43-
import { VscodeClipboardAddon } from 'vs/workbench/contrib/terminal/browser/xterm/vscodeClipboardAddon';
4443

4544
const enum RenderConstants {
4645
SmoothScrollDuration = 125
4746
}
4847

48+
let ClipboardAddon: typeof ClipboardAddonType;
4949
let ImageAddon: typeof ImageAddonType;
5050
let SearchAddon: typeof SearchAddonType;
5151
let SerializeAddon: typeof SerializeAddonType;
@@ -119,7 +119,9 @@ export class XtermTerminal extends Disposable implements IXtermTerminal, IDetach
119119
private _markNavigationAddon: MarkNavigationAddon;
120120
private _shellIntegrationAddon: ShellIntegrationAddon;
121121
private _decorationAddon: DecorationAddon;
122-
private _clipboardAddon: ClipboardAddonType;
122+
123+
// Always on dynamicly imported addons
124+
private _clipboardAddon?: ClipboardAddonType;
123125

124126
// Optional addons
125127
private _searchAddon?: SearchAddonType;
@@ -276,8 +278,17 @@ export class XtermTerminal extends Disposable implements IXtermTerminal, IDetach
276278
this.raw.loadAddon(this._decorationAddon);
277279
this._shellIntegrationAddon = new ShellIntegrationAddon(shellIntegrationNonce, disableShellIntegrationReporting, this._telemetryService, this._logService);
278280
this.raw.loadAddon(this._shellIntegrationAddon);
279-
this._clipboardAddon = this._instantiationService.createInstance(VscodeClipboardAddon);
280-
this.raw.loadAddon(this._clipboardAddon);
281+
this._getClipboardAddonConstructor().then(ClipboardAddon => {
282+
this._clipboardAddon = this._instantiationService.createInstance(ClipboardAddon, undefined, {
283+
async readText(type: ClipboardSelectionType): Promise<string> {
284+
return _clipboardService.readText(type === 'p' ? 'selection' : 'clipboard');
285+
},
286+
async writeText(type: ClipboardSelectionType, text: string): Promise<void> {
287+
return _clipboardService.writeText(text, type === 'p' ? 'selection' : 'clipboard');
288+
}
289+
});
290+
this.raw.loadAddon(this._clipboardAddon);
291+
});
281292

282293
this._anyTerminalFocusContextKey = TerminalContextKeys.focusInAny.bindTo(contextKeyService);
283294
this._anyFocusedTerminalHasSelection = TerminalContextKeys.textSelectedInFocused.bindTo(contextKeyService);
@@ -330,7 +341,7 @@ export class XtermTerminal extends Disposable implements IXtermTerminal, IDetach
330341
this.raw.open(container);
331342
}
332343

333-
// TODO: Move before open to the DOM renderer doesn't initialize
344+
// TODO: Move before open so the DOM renderer doesn't initialize
334345
if (options.enableGpu) {
335346
if (this._shouldLoadWebgl()) {
336347
this._enableWebglRenderer();
@@ -715,6 +726,13 @@ export class XtermTerminal extends Disposable implements IXtermTerminal, IDetach
715726
}
716727
}
717728

729+
protected async _getClipboardAddonConstructor(): Promise<typeof ClipboardAddonType> {
730+
if (!ClipboardAddon) {
731+
ClipboardAddon = (await importAMDNodeModule<typeof import('@xterm/addon-clipboard')>('@xterm/addon-clipboard', 'lib/addon-clipboard.js')).ClipboardAddon;
732+
}
733+
return ClipboardAddon;
734+
}
735+
718736
protected async _getImageAddonConstructor(): Promise<typeof ImageAddonType> {
719737
if (!ImageAddon) {
720738
ImageAddon = (await importAMDNodeModule<typeof import('@xterm/addon-image')>('@xterm/addon-image', 'lib/addon-image.js')).ImageAddon;

0 commit comments

Comments
 (0)