Adds support for column selections if holding alt on mac and shift on windows/linux

This commit is contained in:
Viraj Sinha
2018-06-28 15:55:44 -07:00
parent 8c20a2e26b
commit 3202ddc96d
11 changed files with 291 additions and 58 deletions
+21 -1
View File
@@ -590,6 +590,8 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
if (!wasMondifierKeyOnlyEvent(ev)) {
this.focus();
}
self._keyUp(ev);
}, true);
on(this.textarea, 'keydown', (ev: KeyboardEvent) => this._keyDown(ev), true);
@@ -696,7 +698,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
this.selectionManager = new SelectionManager(this, this.charMeasure);
this.element.addEventListener('mousedown', (e: MouseEvent) => this.selectionManager.onMouseDown(e));
this.selectionManager.on('refresh', data => this.renderer.onSelectionChanged(data.start, data.end));
this.selectionManager.on('refresh', data => this.renderer.onSelectionChanged(data.start, data.end, data.columnSelectMode));
this.selectionManager.on('newselection', text => {
// If there's a new selection, put it into the textarea, focus and select it
// in order to register it as a selection on the OS. This event is fired
@@ -1098,6 +1100,17 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
}
}
/**
* Change the cursor style for different selection modes
*/
public updateCursorStyle(ev: KeyboardEvent): void {
if (this.selectionManager.isColumnSelectMode(ev)) {
this.element.classList.add('xterm-cursor-crosshair');
} else {
this.element.classList.remove('xterm-cursor-crosshair');
}
}
/**
* Display the cursor element
*/
@@ -1415,6 +1428,8 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
const result = evaluateKeyboardEvent(event, this.applicationCursor, this.browser.isMac, this.options.macOptionIsMeta);
this.updateCursorStyle(event);
// if (result.key === C0.DC3) { // XOFF
// this._writeStopped = true;
// } else if (result.key === C0.DC1) { // XON
@@ -1486,6 +1501,11 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
}
}
protected _keyUp(ev: KeyboardEvent): boolean {
this.updateCursorStyle(ev);
return true;
}
/**
* Handle a keypress event.
* Key Resources: