Make reverseIndex scroll region-aware
This was causing a issue when scrollback was 0 as the start of the buffer was getting copied
This commit is contained in:
@@ -464,13 +464,10 @@ export class InputHandler implements IInputHandler {
|
|||||||
let j: number;
|
let j: number;
|
||||||
j = this._terminal.rows - 1 - this._terminal.buffer.scrollBottom;
|
j = this._terminal.rows - 1 - this._terminal.buffer.scrollBottom;
|
||||||
j = this._terminal.rows - 1 + this._terminal.buffer.ybase - j;
|
j = this._terminal.rows - 1 + this._terminal.buffer.ybase - j;
|
||||||
console.log('deleteLines', params);
|
|
||||||
while (param--) {
|
while (param--) {
|
||||||
// test: echo -e '\e[44m\e[1M\e[0m'
|
// test: echo -e '\e[44m\e[1M\e[0m'
|
||||||
// blankLine(true) - xterm/linux behavior
|
// blankLine(true) - xterm/linux behavior
|
||||||
console.log('splice delete row: ' + (row - 1) + '(' + this._terminal.buffer.lines.get(row - 1)[0][1] + ')');
|
|
||||||
this._terminal.buffer.lines.splice(row - 1, 1);
|
this._terminal.buffer.lines.splice(row - 1, 1);
|
||||||
console.log('splice add blank row: ' + (j) + '(' + this._terminal.buffer.lines.get(j)[0][1] + ')');
|
|
||||||
this._terminal.buffer.lines.splice(j, 0, this._terminal.blankLine(true));
|
this._terminal.buffer.lines.splice(j, 0, this._terminal.blankLine(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-98
@@ -1163,133 +1163,44 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Scroll the terminal down 1 row, creating a blank line.
|
* Scroll the terminal down 1 row, creating a blank line.
|
||||||
* @param {boolean} isWrapped Whether the new line is wrapped from the previous
|
* @param isWrapped Whether the new line is wrapped from the previous line.
|
||||||
* line.
|
|
||||||
*/
|
*/
|
||||||
public scroll(isWrapped?: boolean): void {
|
public scroll(isWrapped?: boolean): void {
|
||||||
// The problem is caused when scrollback = 0. This section was written
|
|
||||||
// around the assumption that there would be buffer to trim when necessary.
|
|
||||||
|
|
||||||
|
|
||||||
// shiftElements should be used here
|
|
||||||
|
|
||||||
// If scrollTop is set (non-zero), we should shiftElements
|
|
||||||
// scrollBottom defines the position at which the new element is inserted
|
|
||||||
|
|
||||||
// Note that both scrollBottom and scrollTop need to be handled individually
|
|
||||||
// because they can be set to terminal.rows or 0 respectively
|
|
||||||
|
|
||||||
// Don't mess with ybase temporarily, asking for trouble
|
|
||||||
|
|
||||||
// This should work with minimal effort utilizing the CiruclarList
|
|
||||||
|
|
||||||
// TODO: Need to hold onto top given the if?
|
|
||||||
const newLine = this.blankLine(undefined, isWrapped);
|
const newLine = this.blankLine(undefined, isWrapped);
|
||||||
const topRow = this.buffer.ybase + this.buffer.scrollTop;
|
const topRow = this.buffer.ybase + this.buffer.scrollTop;
|
||||||
let bottomRow = this.buffer.ybase + this.buffer.scrollBottom;
|
let bottomRow = this.buffer.ybase + this.buffer.scrollBottom;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: There's a problem with ybase going beyond scrollback?
|
|
||||||
|
|
||||||
|
|
||||||
console.log('bottomRow', bottomRow);
|
|
||||||
console.log('this.buffer.scrollTop: ' + this.buffer.scrollTop);
|
|
||||||
if (this.buffer.scrollTop === 0) {
|
if (this.buffer.scrollTop === 0) {
|
||||||
|
// Determine whether the buffer is going to be trimmed after insertion.
|
||||||
const willBufferBeTrimmed = this.buffer.lines.length === this.buffer.lines.maxLength;
|
const willBufferBeTrimmed = this.buffer.lines.length === this.buffer.lines.maxLength;
|
||||||
|
|
||||||
// Remove the line first if there is no scrollback so the list is not
|
// Insert the line using the fastest method
|
||||||
// trimmed
|
|
||||||
if (!this.buffer.hasScrollback) {
|
|
||||||
this.buffer.lines.splice(topRow, 1);
|
|
||||||
// Adjust bottomRow to make up for the deleted row
|
|
||||||
// bottomRow--;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bottomRow === this.buffer.lines.length - 1) {
|
if (bottomRow === this.buffer.lines.length - 1) {
|
||||||
// Pushing when possible is faster than splicing
|
|
||||||
this.buffer.lines.push(newLine);
|
this.buffer.lines.push(newLine);
|
||||||
console.log('push');
|
|
||||||
} else {
|
} else {
|
||||||
// Insert a row *below* the bottomRow, pushing the top row into the scrollback
|
this.buffer.lines.splice(bottomRow + 1, 0, newLine);
|
||||||
if (!this.buffer.hasScrollback) {
|
|
||||||
// A line is deleted in this case so bottomRow is pushed up
|
|
||||||
this.buffer.lines.splice(bottomRow, 0, newLine);
|
|
||||||
} else {
|
|
||||||
this.buffer.lines.splice(bottomRow + 1, 0, newLine);
|
|
||||||
}
|
|
||||||
console.log('splice');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only adjust ybase and ydisp when the buffer is not trimmed
|
// Only adjust ybase and ydisp when the buffer is not trimmed
|
||||||
if (!willBufferBeTrimmed) {
|
if (!willBufferBeTrimmed) {
|
||||||
console.log('increment ydisp/ybase');
|
|
||||||
this.buffer.ybase++;
|
this.buffer.ybase++;
|
||||||
this.buffer.ydisp++;
|
this.buffer.ydisp++;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('this.buffer.ybase: ' + this.buffer.ybase);
|
|
||||||
console.log('this.buffer.ydisp: ' + this.buffer.ydisp);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
// scrollTop is non-zero which means no line will be going to the
|
||||||
|
// scrollback, instead we can just shift them in-place.
|
||||||
const scrollRegionHeight = bottomRow - topRow + 1/*as it's zero-based*/;
|
const scrollRegionHeight = bottomRow - topRow + 1/*as it's zero-based*/;
|
||||||
|
|
||||||
console.log('shiftElements');
|
|
||||||
console.log('topRow: ' + topRow + '(' + this.buffer.lines.get(topRow)[0][1] + ')');
|
|
||||||
console.log('scrollRegionHeight: ' + scrollRegionHeight);
|
|
||||||
|
|
||||||
this.buffer.lines.shiftElements(topRow + 1, scrollRegionHeight - 1, -1);
|
this.buffer.lines.shiftElements(topRow + 1, scrollRegionHeight - 1, -1);
|
||||||
this.buffer.lines.set(bottomRow, newLine);
|
this.buffer.lines.set(bottomRow, newLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Move the viewport to the bottom of the buffer unless the user is
|
||||||
|
// scrolling.
|
||||||
if (!this.userScrolling) {
|
if (!this.userScrolling) {
|
||||||
this.buffer.ydisp = this.buffer.ybase;
|
this.buffer.ydisp = this.buffer.ybase;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Flag rows that need updating
|
||||||
// Make room for the new row in lines
|
|
||||||
// const bufferNeedsTrimming = this.buffer.lines.length === this.buffer.lines.maxLength;
|
|
||||||
// if (bufferNeedsTrimming) {
|
|
||||||
// this.buffer.lines.trimStart(1);
|
|
||||||
// this.buffer.ybase--;
|
|
||||||
// this.buffer.ydisp = Math.max(this.buffer.ydisp - 1, 0);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// this.buffer.ybase++;
|
|
||||||
|
|
||||||
// // Scroll the viewport down to the bottom if the user is not scrolling
|
|
||||||
// if (!this.userScrolling) {
|
|
||||||
// this.buffer.ydisp = this.buffer.ybase;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // last line
|
|
||||||
// let row = this.buffer.ybase + this.rows - 1;
|
|
||||||
|
|
||||||
// // subtract the bottom scroll region
|
|
||||||
// row -= this.rows - 1 - this.buffer.scrollBottom;
|
|
||||||
|
|
||||||
// // Same as this?
|
|
||||||
// // row = this.buffer.ybase + this.buffer.scrollBottom;
|
|
||||||
|
|
||||||
// if (row === this.buffer.lines.length) {
|
|
||||||
// // Optimization: pushing is faster than splicing when they amount to the same behavior
|
|
||||||
// this.buffer.lines.push(this.blankLine(undefined, isWrapped));
|
|
||||||
// } else {
|
|
||||||
// // add our new line
|
|
||||||
// this.buffer.lines.splice(row, 0, this.blankLine(undefined, isWrapped));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (this.buffer.scrollTop !== 0) {
|
|
||||||
// if (this.buffer.ybase !== 0) {
|
|
||||||
// this.buffer.ybase--;
|
|
||||||
// if (!this.userScrolling) {
|
|
||||||
// this.buffer.ydisp = this.buffer.ybase;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// this.buffer.lines.splice(this.buffer.ybase + this.buffer.scrollTop, 1);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// this.maxRange();
|
|
||||||
this.updateRange(this.buffer.scrollTop);
|
this.updateRange(this.buffer.scrollTop);
|
||||||
this.updateRange(this.buffer.scrollBottom);
|
this.updateRange(this.buffer.scrollBottom);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user