Replace ISelectionPosition with IBufferRange

Fixes #2480
This commit is contained in:
Daniel Imms
2022-07-28 05:58:15 -07:00
parent 940c93e9cd
commit d1f53e2b02
8 changed files with 32 additions and 78 deletions
+10 -10
View File
@@ -3,7 +3,7 @@
* @license MIT * @license MIT
*/ */
import { Terminal, IDisposable, ITerminalAddon, ISelectionPosition, IDecoration } from 'xterm'; import { Terminal, IDisposable, ITerminalAddon, IBufferRange, IDecoration } from 'xterm';
import { EventEmitter } from 'common/EventEmitter'; import { EventEmitter } from 'common/EventEmitter';
export interface ISearchOptions { export interface ISearchOptions {
@@ -235,14 +235,14 @@ export class SearchAddon implements ITerminalAddon {
let startCol = 0; let startCol = 0;
let startRow = 0; let startRow = 0;
let currentSelection: ISelectionPosition | undefined; let currentSelection: IBufferRange | undefined;
if (this._terminal.hasSelection()) { if (this._terminal.hasSelection()) {
const incremental = searchOptions ? searchOptions.incremental : false; const incremental = searchOptions ? searchOptions.incremental : false;
// 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
currentSelection = this._terminal.getSelectionPosition()!; currentSelection = this._terminal.getSelectionPosition()!;
startRow = incremental ? currentSelection.startRow : currentSelection.endRow; startRow = incremental ? currentSelection.start.y : currentSelection.end.y;
startCol = incremental ? currentSelection.startColumn : currentSelection.endColumn; startCol = incremental ? currentSelection.start.x : currentSelection.end.x;
} }
this._initLinesCache(); this._initLinesCache();
@@ -282,7 +282,7 @@ export class SearchAddon implements ITerminalAddon {
// If there is only one result, wrap back and return selection if it exists. // If there is only one result, wrap back and return selection if it exists.
if (!result && currentSelection) { if (!result && currentSelection) {
searchPosition.startRow = currentSelection.startRow; searchPosition.startRow = currentSelection.start.y;
searchPosition.startCol = 0; searchPosition.startCol = 0;
result = this._findInLine(term, searchPosition, searchOptions); result = this._findInLine(term, searchPosition, searchOptions);
} }
@@ -357,12 +357,12 @@ export class SearchAddon implements ITerminalAddon {
const isReverseSearch = true; const isReverseSearch = true;
const incremental = searchOptions ? searchOptions.incremental : false; const incremental = searchOptions ? searchOptions.incremental : false;
let currentSelection: ISelectionPosition | undefined; let currentSelection: IBufferRange | undefined;
if (this._terminal.hasSelection()) { if (this._terminal.hasSelection()) {
currentSelection = this._terminal.getSelectionPosition()!; currentSelection = this._terminal.getSelectionPosition()!;
// Start from selection start if there is a selection // Start from selection start if there is a selection
startRow = currentSelection.startRow; startRow = currentSelection.start.y;
startCol = currentSelection.startColumn; startCol = currentSelection.start.x;
} }
this._initLinesCache(); this._initLinesCache();
@@ -378,8 +378,8 @@ export class SearchAddon implements ITerminalAddon {
if (!isOldResultHighlighted) { if (!isOldResultHighlighted) {
// If selection was not able to be expanded to the right, then try reverse search // If selection was not able to be expanded to the right, then try reverse search
if (currentSelection) { if (currentSelection) {
searchPosition.startRow = currentSelection.endRow; searchPosition.startRow = currentSelection.end.y;
searchPosition.startCol = currentSelection.endColumn; searchPosition.startCol = currentSelection.end.x;
} }
result = this._findInLine(term, searchPosition, searchOptions, true); result = this._findInLine(term, searchPosition, searchOptions, true);
} }
@@ -443,8 +443,8 @@ export class SerializeAddon implements ITerminalAddon {
const selection = this._terminal?.getSelectionPosition(); const selection = this._terminal?.getSelectionPosition();
if (selection !== undefined) { if (selection !== undefined) {
return handler.serialize({ return handler.serialize({
start: { x: selection.startRow, y: selection.startColumn }, start: { x: selection.start.y, y: selection.start.x },
end: { x: selection.endRow, y: selection.endColumn } end: { x: selection.end.y, y: selection.end.x }
}); });
} }
+11 -7
View File
@@ -21,7 +21,7 @@
* http://linux.die.net/man/7/urxvt * http://linux.die.net/man/7/urxvt
*/ */
import { ICompositionHelper, ITerminal, IBrowser, CustomKeyEventHandler, IViewport, ILinkifier2, CharacterJoinerHandler } from 'browser/Types'; import { ICompositionHelper, ITerminal, IBrowser, CustomKeyEventHandler, IViewport, ILinkifier2, CharacterJoinerHandler, IBufferRange } from 'browser/Types';
import { IRenderer } from 'browser/renderer/Types'; import { IRenderer } from 'browser/renderer/Types';
import { CompositionHelper } from 'browser/input/CompositionHelper'; import { CompositionHelper } from 'browser/input/CompositionHelper';
import { Viewport } from 'browser/Viewport'; import { Viewport } from 'browser/Viewport';
@@ -33,7 +33,7 @@ import * as Browser from 'common/Platform';
import { addDisposableDomListener } from 'browser/Lifecycle'; import { addDisposableDomListener } from 'browser/Lifecycle';
import * as Strings from 'browser/LocalizableStrings'; import * as Strings from 'browser/LocalizableStrings';
import { AccessibilityManager } from './AccessibilityManager'; import { AccessibilityManager } from './AccessibilityManager';
import { ITheme, IMarker, IDisposable, ISelectionPosition, ILinkProvider, IDecorationOptions, IDecoration } from 'xterm'; import { ITheme, IMarker, IDisposable, ILinkProvider, IDecorationOptions, IDecoration } from 'xterm';
import { DomRenderer } from 'browser/renderer/dom/DomRenderer'; import { DomRenderer } from 'browser/renderer/dom/DomRenderer';
import { KeyboardResultType, CoreMouseEventType, CoreMouseButton, CoreMouseAction, ITerminalOptions, ScrollSource, IColorEvent, ColorIndex, ColorRequestType } from 'common/Types'; import { KeyboardResultType, CoreMouseEventType, CoreMouseButton, CoreMouseAction, ITerminalOptions, ScrollSource, IColorEvent, ColorIndex, ColorRequestType } from 'common/Types';
import { evaluateKeyboardEvent } from 'common/input/Keyboard'; import { evaluateKeyboardEvent } from 'common/input/Keyboard';
@@ -993,16 +993,20 @@ export class Terminal extends CoreTerminal implements ITerminal {
return this._selectionService ? this._selectionService.selectionText : ''; return this._selectionService ? this._selectionService.selectionText : '';
} }
public getSelectionPosition(): ISelectionPosition | undefined { public getSelectionPosition(): IBufferRange | undefined {
if (!this._selectionService || !this._selectionService.hasSelection) { if (!this._selectionService || !this._selectionService.hasSelection) {
return undefined; return undefined;
} }
return { return {
startColumn: this._selectionService.selectionStart![0], start: {
startRow: this._selectionService.selectionStart![1], x: this._selectionService.selectionStart![0],
endColumn: this._selectionService.selectionEnd![0], y: this._selectionService.selectionStart![1]
endRow: this._selectionService.selectionEnd![1] },
end: {
x: this._selectionService.selectionEnd![0],
y: this._selectionService.selectionEnd![1]
}
}; };
} }
+3 -3
View File
@@ -3,11 +3,11 @@
* @license MIT * @license MIT
*/ */
import { IDisposable, IMarker, ISelectionPosition, ILinkProvider, IDecorationOptions, IDecoration } from 'xterm'; import { IDisposable, IMarker, ILinkProvider, IDecorationOptions, IDecoration } from 'xterm';
import { IEvent, EventEmitter } from 'common/EventEmitter'; import { IEvent, EventEmitter } from 'common/EventEmitter';
import { ICharacterJoinerService, ICharSizeService, IMouseService, IRenderService, ISelectionService } from 'browser/services/Services'; import { ICharacterJoinerService, ICharSizeService, IMouseService, IRenderService, ISelectionService } from 'browser/services/Services';
import { IRenderDimensions, IRenderer, IRequestRedrawEvent } from 'browser/renderer/Types'; import { IRenderDimensions, IRenderer, IRequestRedrawEvent } from 'browser/renderer/Types';
import { IColorSet, ITerminal, ILinkifier2, IBrowser, IViewport, IColorManager, ICompositionHelper, CharacterJoinerHandler, IRenderDebouncer } from 'browser/Types'; import { IColorSet, ITerminal, ILinkifier2, IBrowser, IViewport, IColorManager, ICompositionHelper, CharacterJoinerHandler, IRenderDebouncer, IBufferRange } from 'browser/Types';
import { IBuffer, IBufferStringIterator, IBufferSet } from 'common/buffer/Types'; import { IBuffer, IBufferStringIterator, IBufferSet } from 'common/buffer/Types';
import { IBufferLine, ICellData, IAttributeData, ICircularList, XtermListener, ICharset, ITerminalOptions } from 'common/Types'; import { IBufferLine, ICellData, IAttributeData, ICircularList, XtermListener, ICharset, ITerminalOptions } from 'common/Types';
import { Buffer } from 'common/buffer/Buffer'; import { Buffer } from 'common/buffer/Buffer';
@@ -107,7 +107,7 @@ export class MockTerminal implements ITerminal {
public getSelection(): string { public getSelection(): string {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
public getSelectionPosition(): ISelectionPosition | undefined { public getSelectionPosition(): IBufferRange | undefined {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
public clearSelection(): void { public clearSelection(): void {
+2 -2
View File
@@ -3,7 +3,7 @@
* @license MIT * @license MIT
*/ */
import { IDecorationOptions, IDecoration, IDisposable, IMarker, ISelectionPosition } from 'xterm'; import { IDecorationOptions, IDecoration, IDisposable, IMarker } from 'xterm';
import { IEvent } from 'common/EventEmitter'; import { IEvent } from 'common/EventEmitter';
import { ICoreTerminal, CharData, ITerminalOptions, IColor } from 'common/Types'; import { ICoreTerminal, CharData, ITerminalOptions, IColor } from 'common/Types';
import { IMouseService, IRenderService } from './services/Services'; import { IMouseService, IRenderService } from './services/Services';
@@ -62,7 +62,7 @@ export interface IPublicTerminal extends IDisposable {
registerDecoration(decorationOptions: IDecorationOptions): IDecoration | undefined; registerDecoration(decorationOptions: IDecorationOptions): IDecoration | undefined;
hasSelection(): boolean; hasSelection(): boolean;
getSelection(): string; getSelection(): string;
getSelectionPosition(): ISelectionPosition | undefined; getSelectionPosition(): IBufferRange | undefined;
clearSelection(): void; clearSelection(): void;
select(column: number, row: number, length: number): void; select(column: number, row: number, length: number): void;
selectAll(): void; selectAll(): void;
+3 -3
View File
@@ -3,8 +3,8 @@
* @license MIT * @license MIT
*/ */
import { Terminal as ITerminalApi, IMarker, IDisposable, ITheme, ILocalizableStrings, ITerminalAddon, ISelectionPosition, IBufferNamespace as IBufferNamespaceApi, IParser, ILinkProvider, IUnicodeHandling, FontWeight, IModes, IDecorationOptions, IDecoration } from 'xterm'; import { Terminal as ITerminalApi, IMarker, IDisposable, ILocalizableStrings, ITerminalAddon, IBufferNamespace as IBufferNamespaceApi, IParser, ILinkProvider, IUnicodeHandling, FontWeight, IModes, IDecorationOptions, IDecoration } from 'xterm';
import { ITerminal } from 'browser/Types'; import { IBufferRange, ITerminal } from 'browser/Types';
import { Terminal as TerminalCore } from 'browser/Terminal'; import { Terminal as TerminalCore } from 'browser/Terminal';
import * as Strings from 'browser/LocalizableStrings'; import * as Strings from 'browser/LocalizableStrings';
import { IEvent } from 'common/EventEmitter'; import { IEvent } from 'common/EventEmitter';
@@ -178,7 +178,7 @@ export class Terminal implements ITerminalApi {
public getSelection(): string { public getSelection(): string {
return this._core.getSelection(); return this._core.getSelection();
} }
public getSelectionPosition(): ISelectionPosition | undefined { public getSelectionPosition(): IBufferRange | undefined {
return this._core.getSelectionPosition(); return this._core.getSelectionPosition();
} }
public clearSelection(): void { public clearSelection(): void {
-25
View File
@@ -711,31 +711,6 @@ declare module 'xterm-headless' {
activate(terminal: Terminal): void; activate(terminal: Terminal): void;
} }
/**
* An object representing a selection 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;
}
/** /**
* An object representing a range within the viewport of the terminal. * An object representing a range within the viewport of the terminal.
*/ */
+1 -26
View File
@@ -917,7 +917,7 @@ declare module 'xterm' {
/** /**
* Gets the selection position or undefined if there is no selection. * Gets the selection position or undefined if there is no selection.
*/ */
getSelectionPosition(): ISelectionPosition | undefined; getSelectionPosition(): IBufferRange | undefined;
/** /**
* Clears the current terminal selection. * Clears the current terminal selection.
@@ -1047,31 +1047,6 @@ declare module 'xterm' {
activate(terminal: Terminal): void; activate(terminal: Terminal): void;
} }
/**
* An object representing a selection 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;
}
/** /**
* An object representing a range within the viewport of the terminal. * An object representing a range within the viewport of the terminal.
*/ */