Fix tsconfigs, IDisposable, and add comments

This commit is contained in:
Ayman Bagabas
2023-09-21 10:26:46 -04:00
parent db5bfc7525
commit b22762b472
9 changed files with 26 additions and 34 deletions
+1 -1
View File
@@ -7,7 +7,7 @@
}, },
"main": "lib/xterm-addon-clipboard.js", "main": "lib/xterm-addon-clipboard.js",
"types": "typings/xterm-addon-clipboard.d.ts", "types": "typings/xterm-addon-clipboard.d.ts",
"repository": "https://github.com/xtermjs/xterm.js", "repository": "https://github.com/xtermjs/xterm.js/tree/master/addons/xterm-addon-clipboard",
"license": "MIT", "license": "MIT",
"keywords": [ "keywords": [
"terminal", "terminal",
@@ -4,18 +4,17 @@
*/ */
import { ClipboardProvider } from './ClipboardProvider'; import { ClipboardProvider } from './ClipboardProvider';
import { IClipboardProvider, ITerminalAddon, Terminal } from 'xterm'; import { IClipboardProvider, IDisposable, ITerminalAddon, Terminal } from 'xterm';
export class ClipboardAddon implements ITerminalAddon { export class ClipboardAddon implements ITerminalAddon {
private _terminal: Terminal | undefined; private _disposable: IDisposable | undefined;
constructor(private _provider: IClipboardProvider = new ClipboardProvider()) {} constructor(private _provider: IClipboardProvider = new ClipboardProvider()) {}
public activate(terminal: Terminal): void { public activate(terminal: Terminal): void {
this._terminal = terminal; this._disposable = terminal.registerClipboardProvider(this._provider);
terminal.registerClipboardProvider(this._provider);
} }
public dispose(): void { public dispose(): void {
this._terminal?.deregisterClipboardProvider(); return this._disposable?.dispose();
} }
} }
@@ -1,7 +1,7 @@
{ {
"compilerOptions": { "compilerOptions": {
"module": "commonjs", "module": "commonjs",
"target": "es2017", "target": "es2021",
"sourceMap": true, "sourceMap": true,
"outDir": "../out", "outDir": "../out",
"rootDir": ".", "rootDir": ".",
@@ -1,9 +1,9 @@
{ {
"compilerOptions": { "compilerOptions": {
"module": "commonjs", "module": "commonjs",
"target": "es2015", "target": "es2021",
"lib": [ "lib": [
"es2015" "es2021"
], ],
"rootDir": ".", "rootDir": ".",
"outDir": "../out-test", "outDir": "../out-test",
+6 -5
View File
@@ -883,12 +883,13 @@ export class Terminal extends CoreTerminal implements ITerminal {
return this.linkifier2.registerLinkProvider(linkProvider); return this.linkifier2.registerLinkProvider(linkProvider);
} }
public registerClipboardProvider(provider: IClipboardProvider): void { public registerClipboardProvider(provider: IClipboardProvider): IDisposable {
this._clipboardProvider = provider; this._clipboardProvider = provider;
} return {
dispose: () => {
public deregisterClipboardProvider(): void { this._clipboardProvider = undefined;
this._clipboardProvider = undefined; }
};
} }
public registerCharacterJoiner(handler: CharacterJoinerHandler): number { public registerCharacterJoiner(handler: CharacterJoinerHandler): number {
+1 -4
View File
@@ -104,10 +104,7 @@ export class MockTerminal implements ITerminal {
public registerDecoration(decorationOptions: IDecorationOptions): IDecoration | undefined { public registerDecoration(decorationOptions: IDecorationOptions): IDecoration | undefined {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
public registerClipboardProvider(provider: IClipboardProvider): void { public registerClipboardProvider(provider: IClipboardProvider): IDisposable {
throw new Error('Method not implemented.');
}
public deregisterClipboardProvider(): void {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
public hasSelection(): boolean { public hasSelection(): boolean {
+2 -5
View File
@@ -168,11 +168,8 @@ export class Terminal extends Disposable implements ITerminalApi {
this._verifyPositiveIntegers(decorationOptions.x ?? 0, decorationOptions.width ?? 0, decorationOptions.height ?? 0); this._verifyPositiveIntegers(decorationOptions.x ?? 0, decorationOptions.width ?? 0, decorationOptions.height ?? 0);
return this._core.registerDecoration(decorationOptions); return this._core.registerDecoration(decorationOptions);
} }
public registerClipboardProvider(provider: IClipboardProvider): void { public registerClipboardProvider(provider: IClipboardProvider): IDisposable {
this._core.registerClipboardProvider(provider); return this._core.registerClipboardProvider(provider);
}
public deregisterClipboardProvider(): void {
this._core.deregisterClipboardProvider();
} }
public hasSelection(): boolean { public hasSelection(): boolean {
return this._core.hasSelection(); return this._core.hasSelection();
-1
View File
@@ -78,7 +78,6 @@ type TerminalProxyCustomOverrides = 'buffer' | (
'registerLinkProvider' | 'registerLinkProvider' |
'registerCharacterJoiner' | 'registerCharacterJoiner' |
'registerClipboardProvider' | 'registerClipboardProvider' |
'deregisterClipboardProvider' |
'deregisterCharacterJoiner' | 'deregisterCharacterJoiner' |
'loadAddon' 'loadAddon'
); );
+8 -9
View File
@@ -1073,12 +1073,7 @@ declare module 'xterm' {
* clipboard to read/write clipboard data. * clipboard to read/write clipboard data.
* @param provider The provider to register. * @param provider The provider to register.
*/ */
registerClipboardProvider(provider: IClipboardProvider): void; registerClipboardProvider(provider: IClipboardProvider): IDisposable;
/**
* Deregisters the active clipboard provider.
*/
deregisterClipboardProvider(): void;
/** /**
* Gets whether the terminal has an active selection. * Gets whether the terminal has an active selection.
@@ -1873,14 +1868,18 @@ declare module 'xterm' {
/** /**
* Sets the clipboard content. * Sets the clipboard content.
* @param selection The clipboard selection to set. * @param selection The clipboard selection to set.
* @param data The base64 encoded data to set. If the data is invalid base64, the clipboard is * @param data The base64 encoded data to set. If the data is invalid
* cleared. * base64, the clipboard is cleared.
*/ */
writeText(selection: ClipboardSelection, data: string): Promise<void>; writeText(selection: ClipboardSelection, data: string): Promise<void>;
} }
/** /**
* Clipboard selection type. * Clipboard selection type. This is used to specify which selection buffer to
* read or write to.
* - SYSTEM `c`: The system clipboard.
* - PRIMARY `p`: The primary clipboard. This is provided for compatibility
* with Linux X11.
*/ */
export const enum ClipboardSelection { export const enum ClipboardSelection {
SYSTEM = 'c', SYSTEM = 'c',