mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Convert selection to EventEmitter2
This commit is contained in:
@@ -108,8 +108,10 @@ export class SelectionManager extends EventEmitter implements ISelectionManager
|
||||
|
||||
private _mouseDownTimeStamp: number;
|
||||
|
||||
private _onNewMouseSelection = new EventEmitter2<string>();
|
||||
public get onNewMouseSelection(): IEvent<string> { return this._onNewMouseSelection.event; }
|
||||
private _onLinuxMouseSelection = new EventEmitter2<string>();
|
||||
public get onLinuxMouseSelection(): IEvent<string> { return this._onLinuxMouseSelection.event; }
|
||||
private _onSelectionChange = new EventEmitter2<void>();
|
||||
public get onSelectionChange(): IEvent<void> { return this._onSelectionChange.event; }
|
||||
|
||||
constructor(
|
||||
private _terminal: ITerminal,
|
||||
@@ -262,7 +264,7 @@ export class SelectionManager extends EventEmitter implements ISelectionManager
|
||||
if (Browser.isLinux && isNewMouseSelection) {
|
||||
const selectionText = this.selectionText;
|
||||
if (selectionText.length) {
|
||||
this._onNewMouseSelection.fire(this.selectionText);
|
||||
this._onLinuxMouseSelection.fire(this.selectionText);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -322,7 +324,7 @@ export class SelectionManager extends EventEmitter implements ISelectionManager
|
||||
public selectAll(): void {
|
||||
this._model.isSelectAllActive = true;
|
||||
this.refresh();
|
||||
this._terminal.emit('selection');
|
||||
this._onSelectionChange.fire();
|
||||
}
|
||||
|
||||
public selectLines(start: number, end: number): void {
|
||||
@@ -332,7 +334,7 @@ export class SelectionManager extends EventEmitter implements ISelectionManager
|
||||
this._model.selectionStart = [0, start];
|
||||
this._model.selectionEnd = [this._terminal.cols, end];
|
||||
this.refresh();
|
||||
this._terminal.emit('selection');
|
||||
this._onSelectionChange.fire();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -650,7 +652,7 @@ export class SelectionManager extends EventEmitter implements ISelectionManager
|
||||
if (this.selectionText.length <= 1 && timeElapsed < ALT_CLICK_MOVE_CURSOR_TIME) {
|
||||
(new AltClickHandler(event, this._terminal)).move();
|
||||
} else if (this.hasSelection) {
|
||||
this._terminal.emit('selection');
|
||||
this._onSelectionChange.fire();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -261,7 +261,6 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
|
||||
this._setup();
|
||||
|
||||
// TODO: Replace EventEmitter with EventEmitter2 internally
|
||||
this.on('selection', () => this._onSelectionChange.fire());
|
||||
this.on('refresh', e => this._onRender.fire(e));
|
||||
|
||||
// TODO: Remove these in v4
|
||||
@@ -271,6 +270,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
|
||||
this.onKey(e => this.emit('key', e.key, e.domEvent));
|
||||
this.onLineFeed(() => this.emit('linefeed'));
|
||||
this.onResize(e => this.emit('resize', e));
|
||||
this.onSelectionChange(() => this.emit('selection'));
|
||||
this.onScroll(e => this.emit('scroll', e));
|
||||
this.onTitleChange(e => this.emit('title', e));
|
||||
}
|
||||
@@ -785,9 +785,10 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
|
||||
this.register(this.renderer.addDisposableListener('resize', (dimensions) => this.viewport.syncScrollArea()));
|
||||
|
||||
this.selectionManager = new SelectionManager(this, this.charMeasure);
|
||||
this.register(this.selectionManager.onSelectionChange(() => this._onSelectionChange.fire()));
|
||||
this.register(addDisposableDomListener(this.element, 'mousedown', (e: MouseEvent) => this.selectionManager.onMouseDown(e)));
|
||||
this.register(this.selectionManager.addDisposableListener('refresh', data => this.renderer.onSelectionChanged(data.start, data.end, data.columnSelectMode)));
|
||||
this.register(this.selectionManager.onNewMouseSelection(text => {
|
||||
this.register(this.selectionManager.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.
|
||||
|
||||
@@ -59,7 +59,7 @@ export function terminadoAttach(term: Terminal, socket: WebSocket, bidirectional
|
||||
socket.addEventListener('message', addonTerminal.__getMessage);
|
||||
|
||||
if (bidirectional) {
|
||||
addonTerminal._core.register(addonTerminal.onData(addonTerminal.__sendData);
|
||||
addonTerminal._core.register(addonTerminal.onData(addonTerminal.__sendData));
|
||||
}
|
||||
addonTerminal._core.register(addonTerminal.onResize(addonTerminal.__setSize));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user