Disable selection manager in mouse mode
This allows the application to take full control of the selection
This commit is contained in:
+4
-2
@@ -903,7 +903,8 @@ export class InputHandler implements IInputHandler {
|
|||||||
this._terminal.vt200Mouse = params[0] === 1000;
|
this._terminal.vt200Mouse = params[0] === 1000;
|
||||||
this._terminal.normalMouse = params[0] > 1000;
|
this._terminal.normalMouse = params[0] > 1000;
|
||||||
this._terminal.mouseEvents = true;
|
this._terminal.mouseEvents = true;
|
||||||
this._terminal.element.style.cursor = 'default';
|
this._terminal.element.classList.add('enable-mouse-events');
|
||||||
|
this._terminal.selectionManager.disable();
|
||||||
this._terminal.log('Binding to mouse events.');
|
this._terminal.log('Binding to mouse events.');
|
||||||
break;
|
break;
|
||||||
case 1004: // send focusin/focusout events
|
case 1004: // send focusin/focusout events
|
||||||
@@ -1096,7 +1097,8 @@ export class InputHandler implements IInputHandler {
|
|||||||
this._terminal.vt200Mouse = false;
|
this._terminal.vt200Mouse = false;
|
||||||
this._terminal.normalMouse = false;
|
this._terminal.normalMouse = false;
|
||||||
this._terminal.mouseEvents = false;
|
this._terminal.mouseEvents = false;
|
||||||
this._terminal.element.style.cursor = '';
|
this._terminal.element.classList.remove('enable-mouse-events');
|
||||||
|
this._terminal.selectionManager.enable();
|
||||||
break;
|
break;
|
||||||
case 1004: // send focusin/focusout events
|
case 1004: // send focusin/focusout events
|
||||||
this._terminal.sendFocus = false;
|
this._terminal.sendFocus = false;
|
||||||
|
|||||||
+36
-7
@@ -13,7 +13,11 @@ export class SelectionManager extends EventEmitter {
|
|||||||
private _selectionStart: [number, number];
|
private _selectionStart: [number, number];
|
||||||
private _selectionEnd: [number, number];
|
private _selectionEnd: [number, number];
|
||||||
|
|
||||||
|
private _bufferTrimListener: any;
|
||||||
private _mouseMoveListener: EventListener;
|
private _mouseMoveListener: EventListener;
|
||||||
|
private _mouseDownListener: EventListener;
|
||||||
|
private _mouseUpListener: EventListener;
|
||||||
|
private _dblClickListener: EventListener;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private _terminal: ITerminal,
|
private _terminal: ITerminal,
|
||||||
@@ -23,16 +27,41 @@ export class SelectionManager extends EventEmitter {
|
|||||||
private _charMeasure: CharMeasure
|
private _charMeasure: CharMeasure
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
this._attachListeners();
|
this._initListeners();
|
||||||
|
this.enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
private _attachListeners() {
|
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._dblClickListener = event => this._onDblClick(<MouseEvent>event);
|
||||||
|
}
|
||||||
|
|
||||||
this._buffer.on('trim', amount => this._onTrim(amount));
|
/**
|
||||||
this._rowContainer.addEventListener('mousedown', event => this._onMouseDown(event));
|
* Disables the selection manager. This is useful for when terminal mouse
|
||||||
this._rowContainer.addEventListener('mouseup', event => this._onMouseUp(event));
|
* are enabled.
|
||||||
this._rowContainer.addEventListener('dblclick', event => this._onDblclick(event));
|
*/
|
||||||
|
public disable() {
|
||||||
|
this._selectionStart = null;
|
||||||
|
this._selectionEnd = null;
|
||||||
|
this.refresh();
|
||||||
|
this._buffer.off('trim', this._bufferTrimListener);
|
||||||
|
this._rowContainer.removeEventListener('mousedown', this._mouseDownListener);
|
||||||
|
this._rowContainer.removeEventListener('mouseup', this._mouseUpListener);
|
||||||
|
this._rowContainer.removeEventListener('dblclick', this._dblClickListener);
|
||||||
|
this._rowContainer.removeEventListener('mousemove', this._mouseMoveListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable the selection manager.
|
||||||
|
*/
|
||||||
|
public enable() {
|
||||||
|
this._buffer.on('trim', this._bufferTrimListener);
|
||||||
|
this._rowContainer.addEventListener('mousedown', this._mouseDownListener);
|
||||||
|
this._rowContainer.addEventListener('mouseup', this._mouseUpListener);
|
||||||
|
this._rowContainer.addEventListener('dblclick', this._dblClickListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public get selectionText(): string {
|
public get selectionText(): string {
|
||||||
@@ -148,7 +177,7 @@ export class SelectionManager extends EventEmitter {
|
|||||||
this._rowContainer.removeEventListener('mousemove', this._mouseMoveListener);
|
this._rowContainer.removeEventListener('mousemove', this._mouseMoveListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _onDblclick(event: MouseEvent) {
|
private _onDblClick(event: MouseEvent) {
|
||||||
const coords = this._getMouseBufferCoords(event);
|
const coords = this._getMouseBufferCoords(event);
|
||||||
if (coords) {
|
if (coords) {
|
||||||
this._selectWordAt(coords);
|
this._selectWordAt(coords);
|
||||||
|
|||||||
@@ -181,6 +181,11 @@
|
|||||||
left: -9999em;
|
left: -9999em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.terminal.enable-mouse-events {
|
||||||
|
/* When mouse events are enabled (eg. tmux), revert to the standard pointer cursor */
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
|
||||||
.terminal .xterm-selection {
|
.terminal .xterm-selection {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user