diff --git a/src/Viewport.ts b/src/Viewport.ts index 11889dae..8a3e4fc0 100644 --- a/src/Viewport.ts +++ b/src/Viewport.ts @@ -8,15 +8,19 @@ import { ITerminal } from './Interfaces'; /** * Represents the viewport of a terminal, the visible area within the larger buffer of output. * Logic for the virtual scroll bar is included in this object. - * @param viewportElement The DOM element acting as the viewport. - * @param scrollArea The DOM element acting as the scroll area. - * @param charMeasureElement A DOM element used to measure the character size of. the terminal. */ export class Viewport { private currentRowHeight: number; private lastRecordedBufferLength: number; private lastRecordedViewportHeight: number; + /** + * Creates a new Viewport. + * @param terminal The terminal this viewport belongs to. + * @param viewportElement The DOM element acting as the viewport. + * @param scrollArea The DOM element acting as the scroll area. + * @param charMeasureElement A DOM element used to measure the character size of. the terminal. + */ constructor( private terminal: ITerminal, private viewportElement: HTMLElement, diff --git a/src/test/test.js b/src/test/test.js index abdc8c17..d8e931fb 100644 --- a/src/test/test.js +++ b/src/test/test.js @@ -189,7 +189,7 @@ describe('xterm.js', function() { it('should scroll down, when a key is pressed and terminal is scrolled up', function () { // Override evaluateKeyEscapeSequence to return cancel code xterm.evaluateKeyEscapeSequence = function() { - return { cancel: true }; + return { key: 'a' }; }; var event = { type: 'keydown', @@ -200,6 +200,7 @@ describe('xterm.js', function() { xterm.ydisp = 0; xterm.ybase = 40; + assert.notEqual(xterm.ydisp, xterm.ybase); xterm.keyDown(event); // Ensure that now the terminal is scrolled to bottom diff --git a/src/utils/Keyboard.test.ts b/src/utils/Keyboard.test.ts deleted file mode 100644 index 618d3331..00000000 --- a/src/utils/Keyboard.test.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { assert } from 'chai'; -import * as Keyboard from './Keyboard'; - -describe('Keyboard', () => { - describe('isModifierOnlyKeyboardEvent', () => { - it('should return true when only modifier keys are used', () => { - // Note that KeyboardEvent.keyCode is deprecated but we're using it to improve browser - // compatibility. This helper returns the `any` type because KeyboardEvent doesn't exist under - // NodeJS. - function createEvent(keyCode: number): any { - return { keyCode }; - } - assert.isTrue(Keyboard.isModifierOnlyKeyboardEvent(createEvent(16))); - assert.isTrue(Keyboard.isModifierOnlyKeyboardEvent(createEvent(17))); - assert.isTrue(Keyboard.isModifierOnlyKeyboardEvent(createEvent(18))); - assert.isTrue(Keyboard.isModifierOnlyKeyboardEvent(createEvent(91))); - assert.isFalse(Keyboard.isModifierOnlyKeyboardEvent(createEvent(19))); - assert.isFalse(Keyboard.isModifierOnlyKeyboardEvent(createEvent(90))); - }); - }); -}); diff --git a/src/utils/Keyboard.ts b/src/utils/Keyboard.ts deleted file mode 100644 index e43cba45..00000000 --- a/src/utils/Keyboard.ts +++ /dev/null @@ -1,22 +0,0 @@ -/** - * xterm.js: xterm, in the browser - * Copyright (c) 2016, SourceLair Private Company (MIT License) - */ - -/** - * Keyboard utilities module. This module contains utilities for dealing with keyboard interaction. - * @module xterm/utils/Keyboard - */ - -/** - * Gets whether a KeyboardEvent is made up entirely of modifier keys. - * - * @param event The event to check. - * @return Whether the KeyboardEvent is made up entirely of modifier keys. - */ -export function isModifierOnlyKeyboardEvent(event: KeyboardEvent): boolean { - return event.keyCode === 16 || // Shift - event.keyCode === 17 || // Control - event.keyCode === 18 || // Alt - event.keyCode === 91; // Meta -} diff --git a/src/xterm.js b/src/xterm.js index 0ef9427d..752d832c 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -2430,12 +2430,10 @@ Terminal.prototype.keyDown = function(ev) { return false; } - // Scroll down to prompt, whenever the user presses a key. - if (!Keyboard.isModifierOnlyKeyboardEvent(ev) && this.ybase !== this.ydisp) { - this.scrollToBottom(); - } - if (!this.compositionHelper.keydown.bind(this.compositionHelper)(ev)) { + if (this.ybase !== this.ydisp) { + this.scrollToBottom(); + } return false; } @@ -2460,6 +2458,11 @@ Terminal.prototype.keyDown = function(ev) { return true; } + // Scroll down to prompt, whenever the user presses a key. + if (this.ybase !== this.ydisp) { + this.scrollToBottom(); + } + this.emit('keydown', ev); this.emit('key', result.key, ev); this.showCursor(); @@ -2724,10 +2727,13 @@ Terminal.prototype.evaluateKeyEscapeSequence = function(ev) { // delete result.key = String.fromCharCode(127); } else if (ev.keyCode === 219) { - // ^[ - escape + // ^[ - Control Sequence Introducer (CSI) result.key = String.fromCharCode(27); + } else if (ev.keyCode === 220) { + // ^\ - String Terminator (ST) + result.key = String.fromCharCode(28); } else if (ev.keyCode === 221) { - // ^] - group sep + // ^] - Operating System Command (OSC) result.key = String.fromCharCode(29); } } else if (!this.browser.isMac && ev.altKey && !ev.ctrlKey && !ev.metaKey) { @@ -5129,7 +5135,6 @@ var wcwidth = (function(opts) { */ Terminal.EventEmitter = EventEmitter; -Terminal.Viewport = Viewport; Terminal.inherits = inherits; /**