Fix selection going to clipboard

Part of #699
This commit is contained in:
Daniel Imms
2017-06-19 15:45:18 -07:00
parent 75b74ac4ff
commit 8811d96a8b
2 changed files with 23 additions and 3 deletions
+15 -2
View File
@@ -293,10 +293,23 @@ export class SelectionManager extends EventEmitter {
/** /**
* Queues a refresh, redrawing the selection on the next opportunity. * Queues a refresh, redrawing the selection on the next opportunity.
*/ */
public refresh(): void { public refresh(fromMouseEvent?: boolean): void {
// Queue the refresh for the renderer
if (!this._refreshAnimationFrame) { if (!this._refreshAnimationFrame) {
this._refreshAnimationFrame = window.requestAnimationFrame(() => this._refresh()); this._refreshAnimationFrame = window.requestAnimationFrame(() => this._refresh());
} }
// If the refresh comes from a mouse event then emit a newselection event
if (!fromMouseEvent) {
return;
}
// TODO: Only do this when the selection has actually changed
// TODO: Ensure we're not doing more work than absolutely necessary, particularly for large selections
// TODO: Only do this on Linux
const selectionText = this.selectionText;
if (selectionText.length) {
this.emit('newselection', this.selectionText);
}
} }
/** /**
@@ -392,7 +405,7 @@ export class SelectionManager extends EventEmitter {
} }
this._addMouseDownListeners(); this._addMouseDownListeners();
this.refresh(); this.refresh(true);
} }
/** /**
+8 -1
View File
@@ -703,7 +703,14 @@ Terminal.prototype.open = function(parent, focus) {
this.viewport = new Viewport(this, this.viewportElement, this.viewportScrollArea, this.charMeasure); this.viewport = new Viewport(this, this.viewportElement, this.viewportScrollArea, this.charMeasure);
this.renderer = new Renderer(this); this.renderer = new Renderer(this);
this.selectionManager = new SelectionManager(this, this.lines, this.rowContainer, this.charMeasure); this.selectionManager = new SelectionManager(this, this.lines, this.rowContainer, this.charMeasure);
this.selectionManager.on('refresh', data => this.renderer.refreshSelection(data.start, data.end)); this.selectionManager.on('refresh', data => {
this.renderer.refreshSelection(data.start, data.end);
});
this.selectionManager.on('newselection', text => {
this.textarea.value = text;
this.textarea.focus();
this.textarea.select();
});
this.on('scroll', () => this.selectionManager.refresh()); this.on('scroll', () => this.selectionManager.refresh());
this.viewportElement.addEventListener('scroll', () => this.selectionManager.refresh()); this.viewportElement.addEventListener('scroll', () => this.selectionManager.refresh());