From 38f4b1389373f95e91c55fa202e1d322123d093b Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sat, 3 Dec 2016 19:32:03 -0800 Subject: [PATCH] Fix selection drop on keyup due to xterm.js --- .../electron-browser/terminalInstance.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts index 5e9e4af0e6e..6e27baaadee 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts @@ -122,7 +122,8 @@ export class TerminalInstance implements ITerminalInstance { return false; }); this._xterm.attachCustomKeydownHandler((event: KeyboardEvent) => { - // Skip processing by xterm.js of commands within commandsToSkipShell + // Skip processing by xterm.js of keyboard events that resolve to commands described + // within commandsToSkipShell const standardKeyboardEvent = new StandardKeyboardEvent(event); const keybinding = new Keybinding(standardKeyboardEvent.asKeybinding()); const resolveResult = this._keybindingService.resolve(keybinding, standardKeyboardEvent.target); @@ -140,8 +141,16 @@ export class TerminalInstance implements ITerminalInstance { // Wait until mouseup has propogated through the DOM before evaluating the new selection // state. setTimeout(() => { - this._terminalHasTextContextKey.set(!window.getSelection().isCollapsed); - console.log('Has text: ' + !window.getSelection().isCollapsed); + this._refreshSelectionContextKey(); + }, 0); + }); + + // xterm.js currently drops selection on keyup as we need to handle this case. + (this._xterm.element).addEventListener('keyup', event => { + // Wait until keyup has propogated through the DOM before evaluating the new selection + // state. + setTimeout(() => { + this._refreshSelectionContextKey(); }, 0); }); @@ -277,6 +286,10 @@ export class TerminalInstance implements ITerminalInstance { this._xterm.clear(); } + private _refreshSelectionContextKey() { + this._terminalHasTextContextKey.set(!window.getSelection().isCollapsed); + } + private sanitizeInput(data: any) { return typeof data === 'string' ? data.replace(TerminalInstance.EOL_REGEX, os.EOL) : data; } -- GitLab