Merge pull request #1104 from Tyriar/902_scrollLines_api

Replace scrollDisp with the more descriptive scrollLines
This commit is contained in:
Daniel Imms
2017-11-04 20:43:06 -07:00
committed by GitHub
9 changed files with 33 additions and 33 deletions
+4 -4
View File
@@ -182,10 +182,10 @@ namespace methods_core {
namespace scrolling { namespace scrolling {
{ {
const t: Terminal = new Terminal(); const t: Terminal = new Terminal();
t.scrollDisp(-1); t.scrollLines(-1);
t.scrollDisp(1); t.scrollLines(1);
t.scrollDisp(-1); t.scrollLines(-1);
t.scrollDisp(1); t.scrollLines(1);
t.scrollToTop(); t.scrollToTop();
t.scrollToBottom(); t.scrollToBottom();
} }
+1 -1
View File
@@ -54,7 +54,7 @@ export interface ITerminal extends ILinkifierAccessor, IBufferAccessor, IElement
* @param data The data to populate in the event. * @param data The data to populate in the event.
*/ */
handler(data: string): void; handler(data: string): void;
scrollDisp(disp: number, suppressScrollEvent?: boolean): void; scrollLines(disp: number, suppressScrollEvent?: boolean): void;
cancel(ev: Event, force?: boolean): boolean | void; cancel(ev: Event, force?: boolean): boolean | void;
log(text: string): void; log(text: string): void;
reset(): void; reset(): void;
+1 -1
View File
@@ -524,7 +524,7 @@ export class SelectionManager extends EventEmitter implements ISelectionManager
*/ */
private _dragScroll(): void { private _dragScroll(): void {
if (this._dragScrollAmount) { if (this._dragScrollAmount) {
this._terminal.scrollDisp(this._dragScrollAmount, false); this._terminal.scrollLines(this._dragScrollAmount, false);
// Re-evaluate selection // Re-evaluate selection
if (this._dragScrollAmount > 0) { if (this._dragScrollAmount > 0) {
this._model.selectionEnd = [this._terminal.cols - 1, this._terminal.buffer.ydisp + this._terminal.rows]; this._model.selectionEnd = [this._terminal.cols - 1, this._terminal.buffer.ydisp + this._terminal.rows];
+11 -11
View File
@@ -12,7 +12,7 @@ const INIT_COLS = 80;
const INIT_ROWS = 24; const INIT_ROWS = 24;
class TestTerminal extends Terminal { class TestTerminal extends Terminal {
public evaluateKeyEscapeSequence(ev: any): {cancel: boolean, key: string, scrollDisp: number} { return this._evaluateKeyEscapeSequence(<KeyboardEvent>ev); } public evaluateKeyEscapeSequence(ev: any): {cancel: boolean, key: string, scrollLines: number} { return this._evaluateKeyEscapeSequence(<KeyboardEvent>ev); }
public keyDown(ev: any): boolean { return this._keyDown(ev); } public keyDown(ev: any): boolean { return this._keyDown(ev); }
public keyPress(ev: any): boolean { return this._keyPress(ev); } public keyPress(ev: any): boolean { return this._keyPress(ev); }
} }
@@ -164,7 +164,7 @@ describe('term.js addons', () => {
}); });
describe('scroll', () => { describe('scroll', () => {
describe('scrollDisp', () => { describe('scrollLines', () => {
let startYDisp; let startYDisp;
beforeEach(() => { beforeEach(() => {
for (let i = 0; i < term.rows * 2; i++) { for (let i = 0; i < term.rows * 2; i++) {
@@ -174,27 +174,27 @@ describe('term.js addons', () => {
}); });
it('should scroll a single line', () => { it('should scroll a single line', () => {
assert.equal(term.buffer.ydisp, startYDisp); assert.equal(term.buffer.ydisp, startYDisp);
term.scrollDisp(-1); term.scrollLines(-1);
assert.equal(term.buffer.ydisp, startYDisp - 1); assert.equal(term.buffer.ydisp, startYDisp - 1);
term.scrollDisp(1); term.scrollLines(1);
assert.equal(term.buffer.ydisp, startYDisp); assert.equal(term.buffer.ydisp, startYDisp);
}); });
it('should scroll multiple lines', () => { it('should scroll multiple lines', () => {
assert.equal(term.buffer.ydisp, startYDisp); assert.equal(term.buffer.ydisp, startYDisp);
term.scrollDisp(-5); term.scrollLines(-5);
assert.equal(term.buffer.ydisp, startYDisp - 5); assert.equal(term.buffer.ydisp, startYDisp - 5);
term.scrollDisp(5); term.scrollLines(5);
assert.equal(term.buffer.ydisp, startYDisp); assert.equal(term.buffer.ydisp, startYDisp);
}); });
it('should not scroll beyond the bounds of the buffer', () => { it('should not scroll beyond the bounds of the buffer', () => {
assert.equal(term.buffer.ydisp, startYDisp); assert.equal(term.buffer.ydisp, startYDisp);
term.scrollDisp(1); term.scrollLines(1);
assert.equal(term.buffer.ydisp, startYDisp); assert.equal(term.buffer.ydisp, startYDisp);
for (let i = 0; i < startYDisp; i++) { for (let i = 0; i < startYDisp; i++) {
term.scrollDisp(-1); term.scrollLines(-1);
} }
assert.equal(term.buffer.ydisp, 0); assert.equal(term.buffer.ydisp, 0);
term.scrollDisp(-1); term.scrollLines(-1);
assert.equal(term.buffer.ydisp, 0); assert.equal(term.buffer.ydisp, 0);
}); });
}); });
@@ -245,7 +245,7 @@ describe('term.js addons', () => {
startYDisp = (term.rows * 2) + 1; startYDisp = (term.rows * 2) + 1;
}); });
it('should scroll to the bottom', () => { it('should scroll to the bottom', () => {
term.scrollDisp(-1); term.scrollLines(-1);
term.scrollToBottom(); term.scrollToBottom();
assert.equal(term.buffer.ydisp, startYDisp); assert.equal(term.buffer.ydisp, startYDisp);
term.scrollPages(-1); term.scrollPages(-1);
@@ -289,7 +289,7 @@ describe('term.js addons', () => {
}); });
assert.equal(term.buffer.ydisp, startYDisp); assert.equal(term.buffer.ydisp, startYDisp);
term.scrollDisp(-1); term.scrollLines(-1);
assert.equal(term.buffer.ydisp, startYDisp - 1); assert.equal(term.buffer.ydisp, startYDisp - 1);
term.keyDown(<KeyboardEvent>{ keyCode: 0 }); term.keyDown(<KeyboardEvent>{ keyCode: 0 });
assert.equal(term.buffer.ydisp, startYDisp - 1); assert.equal(term.buffer.ydisp, startYDisp - 1);
+12 -12
View File
@@ -1124,11 +1124,11 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
/** /**
* Scroll the display of the terminal * Scroll the display of the terminal
* @param {number} disp The number of lines to scroll down (negative scroll up). * @param {number} disp The number of lines to scroll down (negative scroll up).
* @param {boolean} suppressScrollEvent Don't emit the scroll event as scrollDisp. This is used * @param {boolean} suppressScrollEvent Don't emit the scroll event as scrollLines. This is used
* to avoid unwanted events being handled by the viewport when the event was triggered from the * to avoid unwanted events being handled by the viewport when the event was triggered from the
* viewport originally. * viewport originally.
*/ */
public scrollDisp(disp: number, suppressScrollEvent?: boolean): void { public scrollLines(disp: number, suppressScrollEvent?: boolean): void {
if (disp < 0) { if (disp < 0) {
if (this.buffer.ydisp === 0) { if (this.buffer.ydisp === 0) {
return; return;
@@ -1158,21 +1158,21 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
* @param {number} pageCount The number of pages to scroll (negative scrolls up). * @param {number} pageCount The number of pages to scroll (negative scrolls up).
*/ */
public scrollPages(pageCount: number): void { public scrollPages(pageCount: number): void {
this.scrollDisp(pageCount * (this.rows - 1)); this.scrollLines(pageCount * (this.rows - 1));
} }
/** /**
* Scrolls the display of the terminal to the top. * Scrolls the display of the terminal to the top.
*/ */
public scrollToTop(): void { public scrollToTop(): void {
this.scrollDisp(-this.buffer.ydisp); this.scrollLines(-this.buffer.ydisp);
} }
/** /**
* Scrolls the display of the terminal to the bottom. * Scrolls the display of the terminal to the bottom.
*/ */
public scrollToBottom(): void { public scrollToBottom(): void {
this.scrollDisp(this.buffer.ybase - this.buffer.ydisp); this.scrollLines(this.buffer.ybase - this.buffer.ydisp);
} }
/** /**
@@ -1377,8 +1377,8 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
this.writeStopped = false; this.writeStopped = false;
} }
if (result.scrollDisp) { if (result.scrollLines) {
this.scrollDisp(result.scrollDisp); this.scrollLines(result.scrollLines);
return this.cancel(ev, true); return this.cancel(ev, true);
} }
@@ -1410,15 +1410,15 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
* Reference: http://invisible-island.net/xterm/ctlseqs/ctlseqs.html * Reference: http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
* @param ev The keyboard event to be translated to key escape sequence. * @param ev The keyboard event to be translated to key escape sequence.
*/ */
protected _evaluateKeyEscapeSequence(ev: KeyboardEvent): {cancel: boolean, key: string, scrollDisp: number} { protected _evaluateKeyEscapeSequence(ev: KeyboardEvent): {cancel: boolean, key: string, scrollLines: number} {
const result: {cancel: boolean, key: string, scrollDisp: number} = { const result: {cancel: boolean, key: string, scrollLines: number} = {
// Whether to cancel event propogation (NOTE: this may not be needed since the event is // Whether to cancel event propogation (NOTE: this may not be needed since the event is
// canceled at the end of keyDown // canceled at the end of keyDown
cancel: false, cancel: false,
// The new key even to emit // The new key even to emit
key: undefined, key: undefined,
// The number of characters to scroll, if this is defined it will cancel the event // The number of characters to scroll, if this is defined it will cancel the event
scrollDisp: undefined scrollLines: undefined
}; };
const modifiers = (ev.shiftKey ? 1 : 0) | (ev.altKey ? 2 : 0) | (ev.ctrlKey ? 4 : 0) | (ev.metaKey ? 8 : 0); const modifiers = (ev.shiftKey ? 1 : 0) | (ev.altKey ? 2 : 0) | (ev.ctrlKey ? 4 : 0) | (ev.metaKey ? 8 : 0);
switch (ev.keyCode) { switch (ev.keyCode) {
@@ -1578,7 +1578,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
case 33: case 33:
// page up // page up
if (ev.shiftKey) { if (ev.shiftKey) {
result.scrollDisp = -(this.rows - 1); result.scrollLines = -(this.rows - 1);
} else { } else {
result.key = C0.ESC + '[5~'; result.key = C0.ESC + '[5~';
} }
@@ -1586,7 +1586,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
case 34: case 34:
// page down // page down
if (ev.shiftKey) { if (ev.shiftKey) {
result.scrollDisp = this.rows - 1; result.scrollLines = this.rows - 1;
} else { } else {
result.key = C0.ESC + '[6~'; result.key = C0.ESC + '[6~';
} }
+1 -1
View File
@@ -95,7 +95,7 @@ export class Viewport implements IViewport {
private onScroll(ev: Event): void { private onScroll(ev: Event): void {
const newRow = Math.round(this.viewportElement.scrollTop / this.currentRowHeight); const newRow = Math.round(this.viewportElement.scrollTop / this.currentRowHeight);
const diff = newRow - this.terminal.buffer.ydisp; const diff = newRow - this.terminal.buffer.ydisp;
this.terminal.scrollDisp(diff, true); this.terminal.scrollLines(diff, true);
} }
/** /**
+1 -1
View File
@@ -134,7 +134,7 @@ export class SearchHelper {
return false; return false;
} }
this._terminal.selectionManager.setSelection(result.col, result.row, result.term.length); this._terminal.selectionManager.setSelection(result.col, result.row, result.term.length);
this._terminal.scrollDisp(result.row - this._terminal.buffer.ydisp, false); this._terminal.scrollLines(result.row - this._terminal.buffer.ydisp, false);
return true; return true;
} }
} }
+1 -1
View File
@@ -41,7 +41,7 @@ export class MockTerminal implements ITerminal {
off(type: string, listener: IListenerType): void { off(type: string, listener: IListenerType): void {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
scrollDisp(disp: number, suppressScrollEvent: boolean): void { scrollLines(disp: number, suppressScrollEvent: boolean): void {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
cancel(ev: Event, force?: boolean): void { cancel(ev: Event, force?: boolean): void {
+1 -1
View File
@@ -371,7 +371,7 @@ declare module 'xterm' {
* Scroll the display of the terminal * Scroll the display of the terminal
* @param amount The number of lines to scroll down (negative scroll up). * @param amount The number of lines to scroll down (negative scroll up).
*/ */
scrollDisp(amount: number): void; scrollLines(amount: number): void;
/** /**
* Scroll the display of the terminal by a number of pages. * Scroll the display of the terminal by a number of pages.