Skip to content

Commit

Permalink
Retain wrapped line state when copying
Browse files Browse the repository at this point in the history
Fixes #443
  • Loading branch information
Tyriar committed Jun 10, 2017
1 parent a889fef commit 346b517
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/InputHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class InputHandler implements IInputHandler {
this._terminal.y++;
if (this._terminal.y > this._terminal.scrollBottom) {
this._terminal.y--;
this._terminal.scroll();
this._terminal.scroll(true);
}
} else {
if (ch_width === 2) // FIXME: check for xterm behavior
Expand Down
16 changes: 14 additions & 2 deletions src/SelectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,24 @@ export class SelectionManager extends EventEmitter {

// Get middle rows
for (let i = start[1] + 1; i <= end[1] - 1; i++) {
result.push(this._translateBufferLineToString(this._buffer.get(i), true));
const bufferLine = this._buffer.get(i);
const lineText = this._translateBufferLineToString(bufferLine, true);
if (bufferLine.isWrapped) {
result[result.length - 1] += lineText;
} else {
result.push(lineText);
}
}

// Get final row
if (start[1] !== end[1]) {
result.push(this._translateBufferLineToString(this._buffer.get(end[1]), true, 0, end[0]));
const bufferLine = this._buffer.get(end[1]);
const lineText = this._translateBufferLineToString(bufferLine, true, 0, end[0]);
if (bufferLine.isWrapped) {
result[result.length - 1] += lineText;
} else {
result.push(lineText);
}
}

// Format string by replacing non-breaking space chars with regular spaces
Expand Down
17 changes: 13 additions & 4 deletions src/xterm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1116,8 +1116,10 @@ Terminal.prototype.showCursor = function() {

/**
* Scroll the terminal down 1 row, creating a blank line.
* @param {boolean} isWrapped Whether the new line is wrapped from the previous
* line.
*/
Terminal.prototype.scroll = function() {
Terminal.prototype.scroll = function(isWrapped) {
var row;

// Make room for the new row in lines
Expand All @@ -1144,10 +1146,10 @@ Terminal.prototype.scroll = function() {

if (row === this.lines.length) {
// Optimization: pushing is faster than splicing when they amount to the same behavior
this.lines.push(this.blankLine());
this.lines.push(this.blankLine(undefined, isWrapped));
} else {
// add our new line
this.lines.splice(row, 0, this.blankLine());
this.lines.splice(row, 0, this.blankLine(undefined, isWrapped));
}

if (this.scrollTop !== 0) {
Expand Down Expand Up @@ -2106,8 +2108,9 @@ Terminal.prototype.eraseLine = function(y) {
/**
* Return the data array of a blank line
* @param {number} cur First bunch of data for each "blank" character.
* @param {boolean} isWrapped Whether the new line is wrapped from the previous line.
*/
Terminal.prototype.blankLine = function(cur) {
Terminal.prototype.blankLine = function(cur, isWrapped) {
var attr = cur
? this.eraseAttr()
: this.defAttr;
Expand All @@ -2116,6 +2119,12 @@ Terminal.prototype.blankLine = function(cur) {
, line = []
, i = 0;

// TODO: It is not ideal that this is a property on an array, a buffer line
// class should be added that will hold this data and other useful functions.
if (isWrapped) {
line.isWrapped = isWrapped;
}

for (; i < this.cols; i++) {
line[i] = ch;
}
Expand Down

0 comments on commit 346b517

Please sign in to comment.