const NON_BREAKING_SPACE_CHAR = String.fromCharCode(160);
const ALL_NON_BREAKING_SPACE_REGEX = new RegExp(NON_BREAKING_SPACE_CHAR, 'g');
+/**
+ * Represents a position of a word on a line.
+ */
interface IWordPosition {
start: number;
length: number;
}
+/**
+ * A selection mode, this drives how the selection behaves on mouse move.
+ */
+enum SelectionMode {
+ NORMAL,
+ WORD,
+ LINE
+}
+
/**
* A class that manages the selection of the terminal. With help from
* SelectionModel, SelectionManager handles with all logic associated with
private _clickCount: number;
/**
- * Whether line select mode is active, this occurs after a triple click.
+ * The current selection mode.
*/
- private _isLineSelectModeActive: boolean;
-
- /**
- * Whether word select mode is active, this occurs after a double click.
- */
- private _isWordSelectModeActive: boolean;
+ private _activeSelectionMode: SelectionMode;
/**
* A setInterval timer that is active while the mouse is down whose callback
this._model = new SelectionModel(_terminal);
this._lastMouseDownTime = 0;
- this._isLineSelectModeActive = false;
- this._isWordSelectModeActive = false;
+ this._activeSelectionMode = SelectionMode.NORMAL;
}
/**
private _onSingleClick(event: MouseEvent): void {
this._model.selectionStartLength = 0;
this._model.isSelectAllActive = false;
- this._isLineSelectModeActive = false;
- this._isWordSelectModeActive = false;
+ this._activeSelectionMode = SelectionMode.NORMAL;
this._model.selectionStart = this._getMouseBufferCoords(event);
if (this._model.selectionStart) {
this._model.selectionEnd = null;
private _onDoubleClick(event: MouseEvent): void {
const coords = this._getMouseBufferCoords(event);
if (coords) {
- this._isWordSelectModeActive = true;
+ this._activeSelectionMode = SelectionMode.WORD;
this._selectWordAt(coords);
}
}
private _onTripleClick(event: MouseEvent): void {
const coords = this._getMouseBufferCoords(event);
if (coords) {
- this._isLineSelectModeActive = true;
+ this._activeSelectionMode = SelectionMode.LINE;
this._selectLineAt(coords[1]);
}
}
this._model.selectionEnd = this._getMouseBufferCoords(event);
// Select the entire line if line select mode is active.
- if (this._isLineSelectModeActive) {
+ if (this._activeSelectionMode === SelectionMode.LINE) {
if (this._model.selectionEnd[1] < this._model.selectionStart[1]) {
this._model.selectionEnd[0] = 0;
} else {
this._model.selectionEnd[0] = this._terminal.cols;
}
- }
-
- if (this._isWordSelectModeActive) {
+ } else if (this._activeSelectionMode === SelectionMode.WORD) {
this._selectToWordAt(this._model.selectionEnd);
}