mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Merge pull request #379 from Tyriar/378_cannot_scroll_up_1plus_pages
Only scroll to bottom during composition or result.key is evaluated
This commit is contained in:
+2
-1
@@ -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
|
||||
|
||||
@@ -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)));
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,22 +0,0 @@
|
||||
/**
|
||||
* xterm.js: xterm, in the browser
|
||||
* Copyright (c) 2016, SourceLair Private Company <www.sourcelair.com> (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
|
||||
}
|
||||
+8
-5
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user