Skip to content

Commit 346b517

Browse files
committed
Retain wrapped line state when copying
Fixes #443
1 parent a889fef commit 346b517

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

Diff for: src/InputHandler.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class InputHandler implements IInputHandler {
5757
this._terminal.y++;
5858
if (this._terminal.y > this._terminal.scrollBottom) {
5959
this._terminal.y--;
60-
this._terminal.scroll();
60+
this._terminal.scroll(true);
6161
}
6262
} else {
6363
if (ch_width === 2) // FIXME: check for xterm behavior

Diff for: src/SelectionManager.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,24 @@ export class SelectionManager extends EventEmitter {
180180

181181
// Get middle rows
182182
for (let i = start[1] + 1; i <= end[1] - 1; i++) {
183-
result.push(this._translateBufferLineToString(this._buffer.get(i), true));
183+
const bufferLine = this._buffer.get(i);
184+
const lineText = this._translateBufferLineToString(bufferLine, true);
185+
if (bufferLine.isWrapped) {
186+
result[result.length - 1] += lineText;
187+
} else {
188+
result.push(lineText);
189+
}
184190
}
185191

186192
// Get final row
187193
if (start[1] !== end[1]) {
188-
result.push(this._translateBufferLineToString(this._buffer.get(end[1]), true, 0, end[0]));
194+
const bufferLine = this._buffer.get(end[1]);
195+
const lineText = this._translateBufferLineToString(bufferLine, true, 0, end[0]);
196+
if (bufferLine.isWrapped) {
197+
result[result.length - 1] += lineText;
198+
} else {
199+
result.push(lineText);
200+
}
189201
}
190202

191203
// Format string by replacing non-breaking space chars with regular spaces

Diff for: src/xterm.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -1116,8 +1116,10 @@ Terminal.prototype.showCursor = function() {
11161116

11171117
/**
11181118
* Scroll the terminal down 1 row, creating a blank line.
1119+
* @param {boolean} isWrapped Whether the new line is wrapped from the previous
1120+
* line.
11191121
*/
1120-
Terminal.prototype.scroll = function() {
1122+
Terminal.prototype.scroll = function(isWrapped) {
11211123
var row;
11221124

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

11451147
if (row === this.lines.length) {
11461148
// Optimization: pushing is faster than splicing when they amount to the same behavior
1147-
this.lines.push(this.blankLine());
1149+
this.lines.push(this.blankLine(undefined, isWrapped));
11481150
} else {
11491151
// add our new line
1150-
this.lines.splice(row, 0, this.blankLine());
1152+
this.lines.splice(row, 0, this.blankLine(undefined, isWrapped));
11511153
}
11521154

11531155
if (this.scrollTop !== 0) {
@@ -2106,8 +2108,9 @@ Terminal.prototype.eraseLine = function(y) {
21062108
/**
21072109
* Return the data array of a blank line
21082110
* @param {number} cur First bunch of data for each "blank" character.
2111+
* @param {boolean} isWrapped Whether the new line is wrapped from the previous line.
21092112
*/
2110-
Terminal.prototype.blankLine = function(cur) {
2113+
Terminal.prototype.blankLine = function(cur, isWrapped) {
21112114
var attr = cur
21122115
? this.eraseAttr()
21132116
: this.defAttr;
@@ -2116,6 +2119,12 @@ Terminal.prototype.blankLine = function(cur) {
21162119
, line = []
21172120
, i = 0;
21182121

2122+
// TODO: It is not ideal that this is a property on an array, a buffer line
2123+
// class should be added that will hold this data and other useful functions.
2124+
if (isWrapped) {
2125+
line.isWrapped = isWrapped;
2126+
}
2127+
21192128
for (; i < this.cols; i++) {
21202129
line[i] = ch;
21212130
}

0 commit comments

Comments
 (0)