diff --git a/src/Terminal.ts b/src/Terminal.ts index 6da60458e..56205d1e6 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -1535,6 +1535,16 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II return this.selectionManager ? this.selectionManager.hasSelection : false; } + /** + * Selects text within the terminal. + * @param column The column the selection starts at.. + * @param row The row the selection starts at. + * @param length The length of the selection. + */ + public setSelection(column: number, row: number, length: number): void { + this.selectionManager.setSelection(column, row, length); + } + /** * Gets the terminal's current selection, this is useful for implementing copy * behavior outside of xterm.js. diff --git a/src/TestUtils.test.ts b/src/TestUtils.test.ts index 1d5008c8b..f5008a435 100644 --- a/src/TestUtils.test.ts +++ b/src/TestUtils.test.ts @@ -80,6 +80,9 @@ export class MockTerminal implements ITerminal { hasSelection(): boolean { throw new Error('Method not implemented.'); } + setSelection(column: number, row: number, length: number): void { + throw new Error('Method not implemented.'); + } getSelection(): string { throw new Error('Method not implemented.'); } diff --git a/src/Types.ts b/src/Types.ts index 5841626ba..238dbd416 100644 --- a/src/Types.ts +++ b/src/Types.ts @@ -249,6 +249,7 @@ export interface IPublicTerminal extends IDisposable, IEventEmitter { deregisterCharacterJoiner(joinerId: number): void; addMarker(cursorYOffset: number): IMarker; hasSelection(): boolean; + setSelection(column: number, row: number, length: number): void; getSelection(): string; clearSelection(): void; selectAll(): void; diff --git a/src/public/Terminal.ts b/src/public/Terminal.ts index 0c6a77457..3f1cfd0cc 100644 --- a/src/public/Terminal.ts +++ b/src/public/Terminal.ts @@ -96,6 +96,9 @@ export class Terminal implements ITerminalApi { public hasSelection(): boolean { return this._core.hasSelection(); } + public setSelection(column: number, row: number, length: number): void { + this._core.setSelection(column, row, length); + } public getSelection(): string { return this._core.getSelection(); } diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index 0714f55f0..59eebc14f 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -670,6 +670,14 @@ declare module 'xterm' { */ hasSelection(): boolean; + /** + * Selects text within the terminal. + * @param column The column the selection starts at.. + * @param row The row the selection starts at. + * @param length The length of the selection. + */ + setSelection(column: number, row: number, length: number): void; + /** * Gets the terminal's current selection, this is useful for implementing * copy behavior outside of xterm.js.