mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Make Terminal.selectionService private
This commit is contained in:
+13
-5
@@ -9,7 +9,6 @@ import { C0, C1 } from 'common/data/EscapeSequences';
|
||||
import { CHARSETS, DEFAULT_CHARSET } from 'common/data/Charsets';
|
||||
import { wcwidth } from 'common/CharWidth';
|
||||
import { EscapeSequenceParser } from 'common/parser/EscapeSequenceParser';
|
||||
import { IDisposable } from 'xterm';
|
||||
import { Disposable } from 'common/Lifecycle';
|
||||
import { concat } from 'common/TypedArrayUtils';
|
||||
import { StringToUtf32, stringFromCodePoint, utf32ToString, Utf8ToUtf32 } from 'common/input/TextDecoder';
|
||||
@@ -20,6 +19,8 @@ import { NULL_CELL_CODE, NULL_CELL_WIDTH, Attributes, FgFlags, BgFlags } from 'c
|
||||
import { CellData } from 'common/buffer/CellData';
|
||||
import { AttributeData } from 'common/buffer/AttributeData';
|
||||
import { ICoreService } from 'common/services/Services';
|
||||
import { ISelectionService } from 'browser/services/Services';
|
||||
import { IDisposable } from 'common/Types';
|
||||
|
||||
/**
|
||||
* Map collect to glevel. Used in `selectCharset`.
|
||||
@@ -112,6 +113,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
private _utf8Decoder: Utf8ToUtf32 = new Utf8ToUtf32();
|
||||
private _workCell: CellData = new CellData();
|
||||
|
||||
private _selectionService: ISelectionService | undefined;
|
||||
|
||||
private _onCursorMove = new EventEmitter<void>();
|
||||
public get onCursorMove(): IEvent<void> { return this._onCursorMove.event; }
|
||||
private _onLineFeed = new EventEmitter<void>();
|
||||
@@ -297,6 +300,11 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
this._terminal = null;
|
||||
}
|
||||
|
||||
// TODO: When InputHandler moves into common, browser dependencies need to move out
|
||||
public setBrowserServices(selectionService: ISelectionService): void {
|
||||
this._selectionService = selectionService;
|
||||
}
|
||||
|
||||
public parse(data: string): void {
|
||||
// Ensure the terminal is not disposed
|
||||
if (!this._terminal) {
|
||||
@@ -1347,8 +1355,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
if (this._terminal.element) {
|
||||
this._terminal.element.classList.add('enable-mouse-events');
|
||||
}
|
||||
if (this._terminal.selectionService) {
|
||||
this._terminal.selectionService.disable();
|
||||
if (this._selectionService) {
|
||||
this._selectionService.disable();
|
||||
}
|
||||
this._terminal.log('Binding to mouse events.');
|
||||
break;
|
||||
@@ -1539,8 +1547,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
if (this._terminal.element) {
|
||||
this._terminal.element.classList.remove('enable-mouse-events');
|
||||
}
|
||||
if (this._terminal.selectionService) {
|
||||
this._terminal.selectionService.enable();
|
||||
if (this._selectionService) {
|
||||
this._selectionService.enable();
|
||||
}
|
||||
break;
|
||||
case 1004: // send focusin/focusout events
|
||||
|
||||
+32
-32
@@ -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
|
||||
|
||||
Vendored
-3
@@ -9,7 +9,6 @@ import { IEvent, IEventEmitter } from 'common/EventEmitter';
|
||||
import { IColorSet } from 'browser/Types';
|
||||
import { IOptionsService } from 'common/services/Services';
|
||||
import { IBuffer, IBufferSet } from 'common/buffer/Types';
|
||||
import { ISelectionService } from 'browser/services/Services';
|
||||
|
||||
export type CustomKeyEventHandler = (event: KeyboardEvent) => boolean;
|
||||
|
||||
@@ -52,7 +51,6 @@ export interface IInputHandlingTerminal {
|
||||
buffers: IBufferSet;
|
||||
buffer: IBuffer;
|
||||
viewport: IViewport;
|
||||
selectionService: ISelectionService;
|
||||
|
||||
onA11yCharEmitter: IEventEmitter<string>;
|
||||
onA11yTabEmitter: IEventEmitter<number>;
|
||||
@@ -195,7 +193,6 @@ export interface ILinkifierEvent {
|
||||
|
||||
export interface ITerminal extends IPublicTerminal, IElementAccessor, IBufferAccessor, ILinkifierAccessor {
|
||||
screenElement: HTMLElement;
|
||||
selectionService: ISelectionService;
|
||||
browser: IBrowser;
|
||||
writeBuffer: string[];
|
||||
cursorHidden: boolean;
|
||||
|
||||
Reference in New Issue
Block a user