wip: alt forces selection
This commit is contained in:
+32
-18
@@ -91,9 +91,12 @@ export class SelectionManager extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
private _refreshAnimationFrame: number;
|
private _refreshAnimationFrame: number;
|
||||||
|
|
||||||
private _bufferTrimListener: any;
|
/**
|
||||||
|
* Whether selection is enabled.
|
||||||
|
*/
|
||||||
|
private _enabled = true;
|
||||||
|
|
||||||
private _mouseMoveListener: EventListener;
|
private _mouseMoveListener: EventListener;
|
||||||
private _mouseDownListener: EventListener;
|
|
||||||
private _mouseUpListener: EventListener;
|
private _mouseUpListener: EventListener;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@@ -114,10 +117,16 @@ export class SelectionManager extends EventEmitter {
|
|||||||
* Initializes listener variables.
|
* Initializes listener variables.
|
||||||
*/
|
*/
|
||||||
private _initListeners() {
|
private _initListeners() {
|
||||||
this._bufferTrimListener = (amount: number) => this._onTrim(amount);
|
|
||||||
this._mouseMoveListener = event => this._onMouseMove(<MouseEvent>event);
|
this._mouseMoveListener = event => this._onMouseMove(<MouseEvent>event);
|
||||||
this._mouseDownListener = event => this._onMouseDown(<MouseEvent>event);
|
|
||||||
this._mouseUpListener = event => this._onMouseUp(<MouseEvent>event);
|
this._mouseUpListener = event => this._onMouseUp(<MouseEvent>event);
|
||||||
|
|
||||||
|
this._rowContainer.addEventListener('mousedown', event => this._onMouseDown(<MouseEvent>event));
|
||||||
|
|
||||||
|
// Only adjust the selection on trim, shiftElements is rarely used (only in
|
||||||
|
// reverseIndex) and delete in a splice is only ever used when the same
|
||||||
|
// number of elements was just added. Given this is could actually be
|
||||||
|
// beneficial to leave the selection as is for these cases.
|
||||||
|
this._buffer.on('trim', (amount: number) => this._onTrim(amount));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -126,20 +135,14 @@ export class SelectionManager extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
public disable() {
|
public disable() {
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
this._buffer.off('trim', this._bufferTrimListener);
|
this._enabled = false;
|
||||||
this._rowContainer.removeEventListener('mousedown', this._mouseDownListener);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable the selection manager.
|
* Enable the selection manager.
|
||||||
*/
|
*/
|
||||||
public enable() {
|
public enable() {
|
||||||
// Only adjust the selection on trim, shiftElements is rarely used (only in
|
this._enabled = true;
|
||||||
// reverseIndex) and delete in a splice is only ever used when the same
|
|
||||||
// number of elements was just added. Given this is could actually be
|
|
||||||
// beneficial to leave the selection as is for these cases.
|
|
||||||
this._buffer.on('trim', this._bufferTrimListener);
|
|
||||||
this._rowContainer.addEventListener('mousedown', this._mouseDownListener);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -314,6 +317,17 @@ export class SelectionManager extends EventEmitter {
|
|||||||
* @param event The mousedown event.
|
* @param event The mousedown event.
|
||||||
*/
|
*/
|
||||||
private _onMouseDown(event: MouseEvent) {
|
private _onMouseDown(event: MouseEvent) {
|
||||||
|
// Ignore this event when selection is disabled
|
||||||
|
if (!this._enabled) {
|
||||||
|
if (!event.altKey) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// Don't send the mouse down event to the current process
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Only action the primary button
|
// Only action the primary button
|
||||||
if (event.button !== 0) {
|
if (event.button !== 0) {
|
||||||
return;
|
return;
|
||||||
@@ -329,11 +343,11 @@ export class SelectionManager extends EventEmitter {
|
|||||||
this._onShiftClick(event);
|
this._onShiftClick(event);
|
||||||
} else {
|
} else {
|
||||||
if (event.detail === 1) {
|
if (event.detail === 1) {
|
||||||
this._onSingleClick(event);
|
this._onSingleClick(event);
|
||||||
} else if (event.detail === 2) {
|
} else if (event.detail === 2) {
|
||||||
this._onDoubleClick(event);
|
this._onDoubleClick(event);
|
||||||
} else if (event.detail === 3) {
|
} else if (event.detail === 3) {
|
||||||
this._onTripleClick(event);
|
this._onTripleClick(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -479,8 +493,8 @@ export class SelectionManager extends EventEmitter {
|
|||||||
|
|
||||||
// Only draw here if the selection changes.
|
// Only draw here if the selection changes.
|
||||||
if (!previousSelectionEnd ||
|
if (!previousSelectionEnd ||
|
||||||
previousSelectionEnd[0] !== this._model.selectionEnd[0] ||
|
previousSelectionEnd[0] !== this._model.selectionEnd[0] ||
|
||||||
previousSelectionEnd[1] !== this._model.selectionEnd[1]) {
|
previousSelectionEnd[1] !== this._model.selectionEnd[1]) {
|
||||||
this.refresh(true);
|
this.refresh(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -603,7 +617,7 @@ export class SelectionManager extends EventEmitter {
|
|||||||
|
|
||||||
const start = startIndex + charOffset - leftWideCharCount;
|
const start = startIndex + charOffset - leftWideCharCount;
|
||||||
const length = Math.min(endIndex - startIndex + leftWideCharCount + rightWideCharCount + 1/*include endIndex char*/, this._terminal.cols);
|
const length = Math.min(endIndex - startIndex + leftWideCharCount + rightWideCharCount + 1/*include endIndex char*/, this._terminal.cols);
|
||||||
return {start, length};
|
return { start, length };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-1
@@ -517,7 +517,7 @@ Terminal.prototype.initGlobal = function() {
|
|||||||
on(this.element, 'copy', event => {
|
on(this.element, 'copy', event => {
|
||||||
// If mouse events are active it means the selection manager is disabled and
|
// If mouse events are active it means the selection manager is disabled and
|
||||||
// copy should be handled by the host program.
|
// copy should be handled by the host program.
|
||||||
if (this.mouseEvents) {
|
if (!this.selectionManager.hasSelection) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
copyHandler(event, term, this.selectionManager);
|
copyHandler(event, term, this.selectionManager);
|
||||||
|
|||||||
Reference in New Issue
Block a user