Make Terminal.selectionService private

This commit is contained in:
Daniel Imms
2019-06-29 18:50:54 -07:00
parent 3806f67fc0
commit 79d8f05528
3 changed files with 45 additions and 40 deletions
+32 -32
View File
@@ -115,7 +115,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
private _charSizeService: ICharSizeService;
private _mouseService: IMouseService;
private _renderService: IRenderService;
public selectionService: ISelectionService;
private _selectionService: ISelectionService;
// modes
public applicationKeypad: boolean;
@@ -301,7 +301,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
this._inputHandler.onLineFeed(() => this._onLineFeed.fire());
this.register(this._inputHandler);
this.selectionService = this.selectionService || null;
this._selectionService = this._selectionService || null;
this.linkifier = this.linkifier || new Linkifier(this);
this._mouseZoneManager = this._mouseZoneManager || null;
this.soundManager = this.soundManager || new SoundManager(this);
@@ -474,7 +474,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
if (!this.hasSelection()) {
return;
}
copyHandler(event, this.selectionService);
copyHandler(event, this._selectionService);
}));
const pasteHandlerWrapper = (event: ClipboardEvent) => pasteHandler(event, this.textarea, this.bracketedPasteMode, e => this._coreService.triggerDataEvent(e, true));
this.register(addDisposableDomListener(this.textarea, 'paste', pasteHandlerWrapper));
@@ -485,12 +485,12 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
// Firefox doesn't appear to fire the contextmenu event on right click
this.register(addDisposableDomListener(this.element, 'mousedown', (event: MouseEvent) => {
if (event.button === 2) {
rightClickHandler(event, this.textarea, this.screenElement, this.selectionService, this.options.rightClickSelectsWord);
rightClickHandler(event, this.textarea, this.screenElement, this._selectionService, this.options.rightClickSelectsWord);
}
}));
} else {
this.register(addDisposableDomListener(this.element, 'contextmenu', (event: MouseEvent) => {
rightClickHandler(event, this.textarea, this.screenElement, this.selectionService, this.options.rightClickSelectsWord);
rightClickHandler(event, this.textarea, this.screenElement, this._selectionService, this.options.rightClickSelectsWord);
}));
}
@@ -636,15 +636,15 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
this.register(this.onFocus(() => this._renderService.onFocus()));
this.register(this._renderService.onDimensionsChange(() => this.viewport.syncScrollArea()));
this.selectionService = new SelectionService(
this._selectionService = new SelectionService(
(amount: number, suppressEvent: boolean) => this.scrollLines(amount, suppressEvent),
this.element, this.screenElement, this._charSizeService, this._bufferService, this._coreService,
this._mouseService, this.optionsService
);
this.register(this.selectionService.onSelectionChange(() => this._onSelectionChange.fire()));
this.register(addDisposableDomListener(this.element, 'mousedown', (e: MouseEvent) => this.selectionService.onMouseDown(e)));
this.register(this.selectionService.onRedrawRequest(e => this._renderService.onSelectionChanged(e.start, e.end, e.columnSelectMode)));
this.register(this.selectionService.onLinuxMouseSelection(text => {
this.register(this._selectionService.onSelectionChange(() => this._onSelectionChange.fire()));
this.register(addDisposableDomListener(this.element, 'mousedown', (e: MouseEvent) => this._selectionService.onMouseDown(e)));
this.register(this._selectionService.onRedrawRequest(e => this._renderService.onSelectionChanged(e.start, e.end, e.columnSelectMode)));
this.register(this._selectionService.onLinuxMouseSelection(text => {
// If there's a new selection, put it into the textarea, focus and select it
// in order to register it as a selection on the OS. This event is fired
// only on Linux to enable middle click to paste selection.
@@ -654,16 +654,16 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
}));
this.register(this.onScroll(() => {
this.viewport.syncScrollArea();
this.selectionService.refresh();
this._selectionService.refresh();
}));
this.register(addDisposableDomListener(this._viewportElement, 'scroll', () => this.selectionService.refresh()));
this.register(addDisposableDomListener(this._viewportElement, 'scroll', () => this._selectionService.refresh()));
// apply mouse event classes set by escape codes before terminal was attached
this.element.classList.toggle('enable-mouse-events', this.mouseEvents);
if (this.mouseEvents) {
this.selectionService.disable();
this._selectionService.disable();
} else {
this.selectionService.enable();
this._selectionService.enable();
}
if (this.options.screenReaderMode) {
@@ -941,7 +941,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
// Don't send the mouse button to the pty if mouse events are disabled or
// if the selection manager is having selection forced (ie. a modifier is
// held).
if (!this.mouseEvents || this.selectionService.shouldForceSelection(ev)) {
if (!this.mouseEvents || this._selectionService.shouldForceSelection(ev)) {
return;
}
@@ -1072,7 +1072,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
* Change the cursor style for different selection modes
*/
public updateCursorStyle(ev: KeyboardEvent): void {
if (this.selectionService && this.selectionService.shouldColumnSelect(ev)) {
if (this._selectionService && this._selectionService.shouldColumnSelect(ev)) {
this.element.classList.add('column-select');
} else {
this.element.classList.remove('column-select');
@@ -1476,7 +1476,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
* Gets whether the terminal has an active selection.
*/
public hasSelection(): boolean {
return this.selectionService ? this.selectionService.hasSelection : false;
return this._selectionService ? this._selectionService.hasSelection : false;
}
/**
@@ -1486,7 +1486,7 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
* @param length The length of the selection.
*/
public select(column: number, row: number, length: number): void {
this.selectionService.setSelection(column, row, length);
this._selectionService.setSelection(column, row, length);
}
/**
@@ -1494,19 +1494,19 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
* behavior outside of xterm.js.
*/
public getSelection(): string {
return this.selectionService ? this.selectionService.selectionText : '';
return this._selectionService ? this._selectionService.selectionText : '';
}
public getSelectionPosition(): ISelectionPosition | undefined {
if (!this.selectionService.hasSelection) {
if (!this._selectionService.hasSelection) {
return undefined;
}
return {
startColumn: this.selectionService.selectionStart[0],
startRow: this.selectionService.selectionStart[1],
endColumn: this.selectionService.selectionEnd[0],
endRow: this.selectionService.selectionEnd[1]
startColumn: this._selectionService.selectionStart[0],
startRow: this._selectionService.selectionStart[1],
endColumn: this._selectionService.selectionEnd[0],
endRow: this._selectionService.selectionEnd[1]
};
}
@@ -1514,8 +1514,8 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
* Clears the current terminal selection.
*/
public clearSelection(): void {
if (this.selectionService) {
this.selectionService.clearSelection();
if (this._selectionService) {
this._selectionService.clearSelection();
}
}
@@ -1523,14 +1523,14 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
* Selects all text within the terminal.
*/
public selectAll(): void {
if (this.selectionService) {
this.selectionService.selectAll();
if (this._selectionService) {
this._selectionService.selectAll();
}
}
public selectLines(start: number, end: number): void {
if (this.selectionService) {
this.selectionService.selectLines(start, end);
if (this._selectionService) {
this._selectionService.selectLines(start, end);
}
}
@@ -1883,8 +1883,8 @@ export class Terminal extends Disposable implements ITerminal, IDisposable, IInp
this._setup();
this._bufferService.reset();
this._coreService.reset();
if (this.selectionService) {
this.selectionService.reset();
if (this._selectionService) {
this._selectionService.reset();
}
// reattach