Merge remote-tracking branch 'ups/master' into 1128_addons

This commit is contained in:
Daniel Imms
2019-05-12 09:44:09 -07:00
8 changed files with 99 additions and 23 deletions
+27
View File
@@ -43,7 +43,11 @@ 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';
<<<<<<< HEAD
import { ITheme, IMarker, IDisposable, ITerminalAddon } from 'xterm'; import { ITheme, IMarker, IDisposable, ITerminalAddon } from 'xterm';
=======
import { ITheme, IMarker, IDisposable, ISelectionPosition } from 'xterm';
>>>>>>> ups/master
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';
@@ -1539,6 +1543,16 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
return this.selectionManager ? this.selectionManager.hasSelection : false; 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 select(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 * Gets the terminal's current selection, this is useful for implementing copy
* behavior outside of xterm.js. * behavior outside of xterm.js.
@@ -1547,6 +1561,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.
*/ */
+7 -1
View File
@@ -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, ITerminalAddon } from 'xterm'; import { ITheme, IDisposable, IMarker, IEvent, ITerminalAddon, ISelectionPosition } from 'xterm';
import { Terminal } from './Terminal'; import { Terminal } from './Terminal';
import { AttributeData } from './core/buffer/BufferLine'; import { AttributeData } from './core/buffer/BufferLine';
@@ -86,9 +86,15 @@ export class MockTerminal implements ITerminal {
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 -1
View File
@@ -3,7 +3,7 @@
* @license MIT * @license MIT
*/ */
import { ITerminalOptions as IPublicTerminalOptions, IEventEmitter, IDisposable, IMarker, Terminal } from 'xterm'; import { ITerminalOptions as IPublicTerminalOptions, IEventEmitter, IDisposable, IMarker, Terminal, 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';
@@ -250,7 +250,9 @@ export interface IPublicTerminal extends IDisposable, IEventEmitter {
addMarker(cursorYOffset: number): IMarker; addMarker(cursorYOffset: number): IMarker;
hasSelection(): boolean; hasSelection(): boolean;
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;
-6
View File
@@ -5,14 +5,8 @@
import { Terminal } from 'xterm'; import { Terminal } from 'xterm';
// TODO: Don't rely on this private API
export interface ITerminalCore {
selectionManager: any;
}
export interface ISearchAddonTerminal extends Terminal { export interface ISearchAddonTerminal extends Terminal {
__searchHelper?: ISearchHelper; __searchHelper?: ISearchHelper;
_core: ITerminalCore;
} }
export interface ISearchHelper { export interface ISearchHelper {
+9 -13
View File
@@ -35,7 +35,6 @@ export class SearchHelper implements ISearchHelper {
* @return Whether a result was found. * @return Whether a result was found.
*/ */
public findNext(term: string, searchOptions?: ISearchOptions): boolean { public findNext(term: string, searchOptions?: ISearchOptions): boolean {
const selectionManager = this._terminal._core.selectionManager;
const {incremental} = searchOptions; const {incremental} = searchOptions;
let result: ISearchResult; let result: ISearchResult;
@@ -47,13 +46,12 @@ export class SearchHelper implements ISearchHelper {
let startCol: number = 0; let startCol: number = 0;
let startRow = this._terminal.buffer.viewportY; let startRow = this._terminal.buffer.viewportY;
if (selectionManager.selectionEnd) { if (this._terminal.hasSelection()) {
// Start from the selection end if there is a selection // Start from the selection end if there is a selection
// For incremental search, use existing row // For incremental search, use existing row
if (this._terminal.getSelection().length !== 0) { const currentSelection = this._terminal.getSelectionPosition();
startRow = incremental ? selectionManager.selectionStart[1] : selectionManager.selectionEnd[1]; startRow = incremental ? currentSelection.startRow : currentSelection.endRow;
startCol = incremental ? selectionManager.selectionStart[0] : selectionManager.selectionEnd[0]; startCol = incremental ? currentSelection.startColumn : currentSelection.endColumn;
}
} }
this._initLinesCache(); this._initLinesCache();
@@ -109,7 +107,6 @@ export class SearchHelper implements ISearchHelper {
* @return Whether a result was found. * @return Whether a result was found.
*/ */
public findPrevious(term: string, searchOptions?: ISearchOptions): boolean { public findPrevious(term: string, searchOptions?: ISearchOptions): boolean {
const selectionManager = this._terminal._core.selectionManager;
let result: ISearchResult; let result: ISearchResult;
if (!term || term.length === 0) { if (!term || term.length === 0) {
@@ -121,12 +118,11 @@ export class SearchHelper implements ISearchHelper {
let startRow = this._terminal.buffer.viewportY + this._terminal.rows - 1; let startRow = this._terminal.buffer.viewportY + this._terminal.rows - 1;
let startCol = this._terminal.cols; let startCol = this._terminal.cols;
if (selectionManager.selectionStart) { if (this._terminal.hasSelection()) {
// Start from the selection start if there is a selection // Start from the selection start if there is a selection
if (this._terminal.getSelection().length !== 0) { const currentSelection = this._terminal.getSelectionPosition();
startRow = selectionManager.selectionStart[1]; startRow = currentSelection.startRow;
startCol = selectionManager.selectionStart[0]; startCol = currentSelection.startColumn;
}
} }
this._initLinesCache(); this._initLinesCache();
@@ -341,7 +337,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.buffer.viewportY); this._terminal.scrollLines(result.row - this._terminal.buffer.viewportY);
return true; return true;
} }
+8 -1
View File
@@ -89,16 +89,23 @@ describe('API Integration Tests', () => {
it('selection', async function(): Promise<any> { it('selection', async function(): Promise<any> {
this.timeout(10000); this.timeout(10000);
await openTerminal({ rows: 5 }); await openTerminal({ rows: 5, cols: 5 });
await page.evaluate(`window.term.write('\\n\\nfoo\\n\\n\\rbar\\n\\n\\rbaz')`); await page.evaluate(`window.term.write('\\n\\nfoo\\n\\n\\rbar\\n\\n\\rbaz')`);
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()`), '');
assert.deepEqual(await page.evaluate(`window.term.getSelectionPosition()`), undefined);
await page.evaluate(`window.term.selectAll()`); await page.evaluate(`window.term.selectAll()`);
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()`), '\n\nfoo\n\nbar\n\nbaz'); assert.equal(await page.evaluate(`window.term.getSelection()`), '\n\nfoo\n\nbar\n\nbaz');
assert.deepEqual(await page.evaluate(`window.term.getSelectionPosition()`), { startColumn: 0, startRow: 0, endColumn: 5, endRow: 6 });
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()`), '');
assert.deepEqual(await page.evaluate(`window.term.getSelectionPosition()`), undefined);
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.getSelection()`), 'oo');
assert.deepEqual(await page.evaluate(`window.term.getSelectionPosition()`), { startColumn: 1, startRow: 2, endColumn: 3, endRow: 2 });
}); });
it('focus, blur', async function(): Promise<any> { it('focus, blur', async function(): Promise<any> {
+7 -1
View File
@@ -3,7 +3,7 @@
* @license MIT * @license MIT
*/ */
import { Terminal as ITerminalApi, ITerminalOptions, IMarker, IDisposable, ILinkMatcherOptions, ITheme, ILocalizableStrings, ITerminalAddon, IBuffer as IBufferApi, IBufferLine as IBufferLineApi, IBufferCell as IBufferCellApi } from 'xterm'; import { Terminal as ITerminalApi, ITerminalOptions, IMarker, IDisposable, ILinkMatcherOptions, ITheme, ILocalizableStrings, ITerminalAddon, ISelectionPosition, IBuffer as IBufferApi, IBufferLine as IBufferLineApi, IBufferCell as IBufferCellApi } 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,9 +96,15 @@ export class Terminal implements ITerminalApi {
public hasSelection(): boolean { public hasSelection(): boolean {
return this._core.hasSelection(); return this._core.hasSelection();
} }
public select(column: number, row: number, length: number): void {
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();
} }
+38
View File
@@ -676,11 +676,24 @@ declare module 'xterm' {
*/ */
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.
*/ */
@@ -878,6 +891,31 @@ declare module 'xterm' {
activate(terminal: Terminal): void; activate(terminal: Terminal): 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