Expose getSelectionPosition and select APIs instead
This commit is contained in:
+15
-2
@@ -43,7 +43,7 @@ import { DEFAULT_BELL_SOUND, SoundManager } from './SoundManager';
|
|||||||
import { MouseZoneManager } from './MouseZoneManager';
|
import { MouseZoneManager } from './MouseZoneManager';
|
||||||
import { AccessibilityManager } from './AccessibilityManager';
|
import { AccessibilityManager } from './AccessibilityManager';
|
||||||
import { ScreenDprMonitor } from './ui/ScreenDprMonitor';
|
import { ScreenDprMonitor } from './ui/ScreenDprMonitor';
|
||||||
import { ITheme, IMarker, IDisposable } from 'xterm';
|
import { ITheme, IMarker, IDisposable, ISelectionPosition } from 'xterm';
|
||||||
import { removeTerminalFromCache } from './renderer/atlas/CharAtlasCache';
|
import { removeTerminalFromCache } from './renderer/atlas/CharAtlasCache';
|
||||||
import { DomRenderer } from './renderer/dom/DomRenderer';
|
import { DomRenderer } from './renderer/dom/DomRenderer';
|
||||||
import { IKeyboardEvent } from './common/Types';
|
import { IKeyboardEvent } from './common/Types';
|
||||||
@@ -1541,7 +1541,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
|
|||||||
* @param row The row the selection starts at.
|
* @param row The row the selection starts at.
|
||||||
* @param length The length of the selection.
|
* @param length The length of the selection.
|
||||||
*/
|
*/
|
||||||
public setSelection(column: number, row: number, length: number): void {
|
public select(column: number, row: number, length: number): void {
|
||||||
this.selectionManager.setSelection(column, row, length);
|
this.selectionManager.setSelection(column, row, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1553,6 +1553,19 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
|
|||||||
return this.selectionManager ? this.selectionManager.selectionText : '';
|
return this.selectionManager ? this.selectionManager.selectionText : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getSelectionPosition(): ISelectionPosition | undefined {
|
||||||
|
if (!this.selectionManager.hasSelection) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
startColumn: this.selectionManager.selectionStart[0],
|
||||||
|
startRow: this.selectionManager.selectionStart[1],
|
||||||
|
endColumn: this.selectionManager.selectionEnd[0],
|
||||||
|
endRow: this.selectionManager.selectionEnd[1]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the current terminal selection.
|
* Clears the current terminal selection.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { IBufferLine, ICellData, IAttributeData } from './core/Types';
|
|||||||
import { ICircularList, XtermListener } from './common/Types';
|
import { ICircularList, XtermListener } from './common/Types';
|
||||||
import { Buffer } from './Buffer';
|
import { Buffer } from './Buffer';
|
||||||
import * as Browser from './common/Platform';
|
import * as Browser from './common/Platform';
|
||||||
import { ITheme, IDisposable, IMarker, IEvent } from 'xterm';
|
import { ITheme, IDisposable, IMarker, IEvent, ISelectionPosition } from 'xterm';
|
||||||
import { Terminal } from './Terminal';
|
import { Terminal } from './Terminal';
|
||||||
import { AttributeData } from './core/buffer/BufferLine';
|
import { AttributeData } from './core/buffer/BufferLine';
|
||||||
|
|
||||||
@@ -80,15 +80,18 @@ export class MockTerminal implements ITerminal {
|
|||||||
hasSelection(): boolean {
|
hasSelection(): boolean {
|
||||||
throw new Error('Method not implemented.');
|
throw new Error('Method not implemented.');
|
||||||
}
|
}
|
||||||
setSelection(column: number, row: number, length: number): void {
|
|
||||||
throw new Error('Method not implemented.');
|
|
||||||
}
|
|
||||||
getSelection(): string {
|
getSelection(): string {
|
||||||
throw new Error('Method not implemented.');
|
throw new Error('Method not implemented.');
|
||||||
}
|
}
|
||||||
|
getSelectionPosition(): ISelectionPosition | undefined {
|
||||||
|
throw new Error('Method not implemented.');
|
||||||
|
}
|
||||||
clearSelection(): void {
|
clearSelection(): void {
|
||||||
throw new Error('Method not implemented.');
|
throw new Error('Method not implemented.');
|
||||||
}
|
}
|
||||||
|
select(column: number, row: number, length: number): void {
|
||||||
|
throw new Error('Method not implemented.');
|
||||||
|
}
|
||||||
selectAll(): void {
|
selectAll(): void {
|
||||||
throw new Error('Method not implemented.');
|
throw new Error('Method not implemented.');
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -3,7 +3,7 @@
|
|||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ITerminalOptions as IPublicTerminalOptions, IEventEmitter, IDisposable, IMarker } from 'xterm';
|
import { ITerminalOptions as IPublicTerminalOptions, IEventEmitter, IDisposable, IMarker, ISelectionPosition } from 'xterm';
|
||||||
import { IColorSet, IRenderer } from './renderer/Types';
|
import { IColorSet, IRenderer } from './renderer/Types';
|
||||||
import { ICharset, IAttributeData, ICellData, IBufferLine, CharData } from './core/Types';
|
import { ICharset, IAttributeData, ICellData, IBufferLine, CharData } from './core/Types';
|
||||||
import { ICircularList } from './common/Types';
|
import { ICircularList } from './common/Types';
|
||||||
@@ -249,9 +249,10 @@ export interface IPublicTerminal extends IDisposable, IEventEmitter {
|
|||||||
deregisterCharacterJoiner(joinerId: number): void;
|
deregisterCharacterJoiner(joinerId: number): void;
|
||||||
addMarker(cursorYOffset: number): IMarker;
|
addMarker(cursorYOffset: number): IMarker;
|
||||||
hasSelection(): boolean;
|
hasSelection(): boolean;
|
||||||
setSelection(column: number, row: number, length: number): void;
|
|
||||||
getSelection(): string;
|
getSelection(): string;
|
||||||
|
getSelectionPosition(): ISelectionPosition | undefined;
|
||||||
clearSelection(): void;
|
clearSelection(): void;
|
||||||
|
select(column: number, row: number, length: number): void;
|
||||||
selectAll(): void;
|
selectAll(): void;
|
||||||
selectLines(start: number, end: number): void;
|
selectLines(start: number, end: number): void;
|
||||||
dispose(): void;
|
dispose(): void;
|
||||||
|
|||||||
@@ -341,7 +341,7 @@ export class SearchHelper implements ISearchHelper {
|
|||||||
this._terminal.clearSelection();
|
this._terminal.clearSelection();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this._terminal._core.selectionManager.setSelection(result.col, result.row, result.term.length);
|
this._terminal.select(result.col, result.row, result.term.length);
|
||||||
this._terminal.scrollLines(result.row - this._terminal._core.buffer.ydisp);
|
this._terminal.scrollLines(result.row - this._terminal._core.buffer.ydisp);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ describe('API Integration Tests', () => {
|
|||||||
await page.evaluate(`window.term.clearSelection()`);
|
await page.evaluate(`window.term.clearSelection()`);
|
||||||
assert.equal(await page.evaluate(`window.term.hasSelection()`), false);
|
assert.equal(await page.evaluate(`window.term.hasSelection()`), false);
|
||||||
assert.equal(await page.evaluate(`window.term.getSelection()`), '');
|
assert.equal(await page.evaluate(`window.term.getSelection()`), '');
|
||||||
await page.evaluate(`window.term.setSelection(1, 2, 2)`)
|
await page.evaluate(`window.term.select(1, 2, 2)`)
|
||||||
assert.equal(await page.evaluate(`window.term.hasSelection()`), true);
|
assert.equal(await page.evaluate(`window.term.hasSelection()`), true);
|
||||||
assert.equal(await page.evaluate(`window.term.getSelection()`), 'oo');
|
assert.equal(await page.evaluate(`window.term.getSelection()`), 'oo');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Terminal as ITerminalApi, ITerminalOptions, IMarker, IDisposable, ILinkMatcherOptions, ITheme, ILocalizableStrings, IBuffer as IBufferApi, IBufferLine as IBufferLineApi, IBufferCell as IBufferCellApi } from 'xterm';
|
import { Terminal as ITerminalApi, ITerminalOptions, IMarker, IDisposable, ILinkMatcherOptions, ITheme, ILocalizableStrings, IBuffer as IBufferApi, IBufferLine as IBufferLineApi, IBufferCell as IBufferCellApi, ISelectionPosition } from 'xterm';
|
||||||
import { ITerminal, IBuffer } from '../Types';
|
import { ITerminal, IBuffer } from '../Types';
|
||||||
import { IBufferLine } from '../core/Types';
|
import { IBufferLine } from '../core/Types';
|
||||||
import { Terminal as TerminalCore } from '../Terminal';
|
import { Terminal as TerminalCore } from '../Terminal';
|
||||||
@@ -96,12 +96,15 @@ export class Terminal implements ITerminalApi {
|
|||||||
public hasSelection(): boolean {
|
public hasSelection(): boolean {
|
||||||
return this._core.hasSelection();
|
return this._core.hasSelection();
|
||||||
}
|
}
|
||||||
public setSelection(column: number, row: number, length: number): void {
|
public select(column: number, row: number, length: number): void {
|
||||||
this._core.setSelection(column, row, length);
|
this._core.select(column, row, length);
|
||||||
}
|
}
|
||||||
public getSelection(): string {
|
public getSelection(): string {
|
||||||
return this._core.getSelection();
|
return this._core.getSelection();
|
||||||
}
|
}
|
||||||
|
public getSelectionPosition(): ISelectionPosition | undefined {
|
||||||
|
return this._core.getSelectionPosition();
|
||||||
|
}
|
||||||
public clearSelection(): void {
|
public clearSelection(): void {
|
||||||
this._core.clearSelection();
|
this._core.clearSelection();
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+38
-8
@@ -670,25 +670,30 @@ declare module 'xterm' {
|
|||||||
*/
|
*/
|
||||||
hasSelection(): boolean;
|
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
|
* Gets the terminal's current selection, this is useful for implementing
|
||||||
* copy behavior outside of xterm.js.
|
* copy behavior outside of xterm.js.
|
||||||
*/
|
*/
|
||||||
getSelection(): string;
|
getSelection(): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the selection position or undefined if there is no selection.
|
||||||
|
*/
|
||||||
|
getSelectionPosition(): ISelectionPosition | undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the current terminal selection.
|
* Clears the current terminal selection.
|
||||||
*/
|
*/
|
||||||
clearSelection(): void;
|
clearSelection(): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
select(column: number, row: number, length: number): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Selects all text within the terminal.
|
* Selects all text within the terminal.
|
||||||
*/
|
*/
|
||||||
@@ -872,6 +877,31 @@ declare module 'xterm' {
|
|||||||
static applyAddon(addon: any): void;
|
static applyAddon(addon: any): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An object representing a selecrtion within the terminal.
|
||||||
|
*/
|
||||||
|
interface ISelectionPosition {
|
||||||
|
/**
|
||||||
|
* The start column of the selection.
|
||||||
|
*/
|
||||||
|
startColumn: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The start row of the selection.
|
||||||
|
*/
|
||||||
|
startRow: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The end column of the selection.
|
||||||
|
*/
|
||||||
|
endColumn: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The end row of the selection.
|
||||||
|
*/
|
||||||
|
endRow: number;
|
||||||
|
}
|
||||||
|
|
||||||
interface IBuffer {
|
interface IBuffer {
|
||||||
/**
|
/**
|
||||||
* The y position of the cursor. This ranges between `0` (when the
|
* The y position of the cursor. This ranges between `0` (when the
|
||||||
|
|||||||
Reference in New Issue
Block a user