Merge branch 'master' into 553_find_api

This commit is contained in:
Daniel Imms
2017-06-22 19:37:18 -07:00
committed by GitHub
7 changed files with 136 additions and 33 deletions
+23 -5
View File
@@ -2,10 +2,11 @@
* @license MIT
*/
import * as Mouse from './utils/Mouse';
import * as Browser from './utils/Browser';
import { CharMeasure } from './utils/CharMeasure';
import { CircularList } from './utils/CircularList';
import { EventEmitter } from './EventEmitter';
import * as Mouse from './utils/Mouse';
import { ITerminal } from './Interfaces';
import { SelectionModel } from './SelectionModel';
import { translateBufferLineToString } from './utils/BufferLine';
@@ -187,7 +188,12 @@ export class SelectionManager extends EventEmitter {
* Gets whether there is an active text selection.
*/
public get hasSelection(): boolean {
return !!this._model.finalSelectionStart && !!this._model.finalSelectionEnd;
const start = this._model.finalSelectionStart;
const end = this._model.finalSelectionEnd;
if (!start || !end) {
return false;
}
return start[0] !== end[0] || start[1] !== end[1];
}
/**
@@ -247,11 +253,23 @@ export class SelectionManager extends EventEmitter {
/**
* Queues a refresh, redrawing the selection on the next opportunity.
* @param isNewSelection Whether the selection should be registered as a new
* selection on Linux.
*/
public refresh(): void {
public refresh(isNewSelection?: boolean): void {
// Queue the refresh for the renderer
if (!this._refreshAnimationFrame) {
this._refreshAnimationFrame = window.requestAnimationFrame(() => this._refresh());
}
// 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) {
const selectionText = this.selectionText;
if (selectionText.length) {
this.emit('newselection', this.selectionText);
}
}
}
/**
@@ -347,7 +365,7 @@ export class SelectionManager extends EventEmitter {
}
this._addMouseDownListeners();
this.refresh();
this.refresh(true);
}
/**
@@ -502,7 +520,7 @@ export class SelectionManager extends EventEmitter {
if (!previousSelectionEnd ||
previousSelectionEnd[0] !== this._model.selectionEnd[0] ||
previousSelectionEnd[1] !== this._model.selectionEnd[1]) {
this.refresh();
this.refresh(true);
}
}