Convert marker dispose, selection manager newselection

This commit is contained in:
Daniel Imms
2019-04-07 14:09:31 -04:00
parent 625e168e1b
commit 6ff81c43f6
3 changed files with 15 additions and 7 deletions
+6 -2
View File
@@ -10,6 +10,7 @@ import { IMarker } from 'xterm';
import { BufferLine, CellData, AttributeData } from './BufferLine';
import { reflowLargerApplyNewLayout, reflowLargerCreateNewLayout, reflowLargerGetLinesToRemove, reflowSmallerGetNewLineLengths } from './BufferReflow';
import { DEFAULT_COLOR } from './renderer/atlas/Types';
import { EventEmitter2, IEvent } from './common/EventEmitter2';
export const DEFAULT_ATTR = (0 << 18) | (DEFAULT_COLOR << 9) | (256 << 0);
@@ -615,7 +616,7 @@ export class Buffer implements IBuffer {
marker.line -= event.amount;
}
}));
marker.register(marker.addDisposableListener('dispose', () => this._removeMarker(marker)));
marker.register(marker.onDispose(() => this._removeMarker(marker)));
return marker;
}
@@ -636,6 +637,9 @@ export class Marker extends EventEmitter implements IMarker {
public get id(): number { return this._id; }
private _onDispose = new EventEmitter2<void>();
public get onDispose(): IEvent<void> { return this._onDispose.event; }
constructor(
public line: number
) {
@@ -648,7 +652,7 @@ export class Marker extends EventEmitter implements IMarker {
}
this.isDisposed = true;
// Emit before super.dispose such that dispose listeners get a change to react
this.emit('dispose');
this._onDispose.fire();
super.dispose();
}
}
+8 -4
View File
@@ -12,6 +12,7 @@ import { SelectionModel } from './SelectionModel';
import { AltClickHandler } from './handlers/AltClickHandler';
import { CellData } from './BufferLine';
import { IDisposable } from 'xterm';
import { EventEmitter2, IEvent } from './common/EventEmitter2';
/**
* The number of pixels the mouse needs to be above or below the viewport in
@@ -107,6 +108,9 @@ export class SelectionManager extends EventEmitter implements ISelectionManager
private _mouseDownTimeStamp: number;
private _onNewMouseSelection = new EventEmitter2<string>();
public get onNewMouseSelection(): IEvent<string> { return this._onNewMouseSelection.event; }
constructor(
private _terminal: ITerminal,
private _charMeasure: CharMeasure
@@ -244,10 +248,10 @@ export class SelectionManager extends EventEmitter implements ISelectionManager
/**
* Queues a refresh, redrawing the selection on the next opportunity.
* @param isNewSelection Whether the selection should be registered as a new
* @param isNewMouseSelection Whether the selection should be registered as a new
* selection on Linux.
*/
public refresh(isNewSelection?: boolean): void {
public refresh(isNewMouseSelection?: boolean): void {
// Queue the refresh for the renderer
if (!this._refreshAnimationFrame) {
this._refreshAnimationFrame = window.requestAnimationFrame(() => this._refresh());
@@ -255,10 +259,10 @@ export class SelectionManager extends EventEmitter implements ISelectionManager
// If the platform is Linux and the refresh call comes from a mouse event,
// we need to update the selection for middle click to paste selection.
if (Browser.isLinux && isNewSelection) {
if (Browser.isLinux && isNewMouseSelection) {
const selectionText = this.selectionText;
if (selectionText.length) {
this.emit('newselection', this.selectionText);
this._onNewMouseSelection.fire(this.selectionText);
}
}
}
+1 -1
View File
@@ -783,7 +783,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
this.selectionManager = new SelectionManager(this, this.charMeasure);
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.addDisposableListener('newselection', text => {
this.register(this.selectionManager.onNewMouseSelection(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.