* @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';
* A string containing all characters that are considered word separated by the
* double click to select work logic.
*/
-const WORD_SEPARATORS = ' ()[]{}:\'"';
+const WORD_SEPARATORS = ' ()[]{}\'"';
// TODO: Move these constants elsewhere, they belong in a buffer or buffer
// data/line class.
*/
public setBuffer(buffer: CircularList<any>): void {
this._buffer = buffer;
+ this.clearSelection();
}
/**
* 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];
}
/**
// and joining the array into a multi-line string.
const formattedResult = result.map(line => {
return line.replace(ALL_NON_BREAKING_SPACE_REGEX, ' ');
- }).join('\n');
+ }).join(Browser.isMSWindows ? '\r\n' : '\n');
return formattedResult;
}
/**
* 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);
+ }
+ }
}
/**
}
this._addMouseDownListeners();
- this.refresh();
+ this.refresh(true);
}
/**
if (!previousSelectionEnd ||
previousSelectionEnd[0] !== this._model.selectionEnd[0] ||
previousSelectionEnd[1] !== this._model.selectionEnd[1]) {
- this.refresh();
+ this.refresh(true);
}
}