Skip to content

Commit 55f51ad

Browse files
authored
Merge pull request #693 from Tyriar/443_retain_wrapped_lines_copy
Retain wrapped line state when copying
2 parents 5f9ad5c + 405d1ee commit 55f51ad

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
@@ -1117,8 +1117,10 @@ Terminal.prototype.showCursor = function() {
11171117

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

11241126
// Make room for the new row in lines
@@ -1145,10 +1147,10 @@ Terminal.prototype.scroll = function() {
11451147

11461148
if (row === this.lines.length) {
11471149
// Optimization: pushing is faster than splicing when they amount to the same behavior
1148-
this.lines.push(this.blankLine());
1150+
this.lines.push(this.blankLine(undefined, isWrapped));
11491151
} else {
11501152
// add our new line
1151-
this.lines.splice(row, 0, this.blankLine());
1153+
this.lines.splice(row, 0, this.blankLine(undefined, isWrapped));
11521154
}
11531155

11541156
if (this.scrollTop !== 0) {
@@ -2107,8 +2109,9 @@ Terminal.prototype.eraseLine = function(y) {
21072109
/**
21082110
* Return the data array of a blank line
21092111
* @param {number} cur First bunch of data for each "blank" character.
2112+
* @param {boolean} isWrapped Whether the new line is wrapped from the previous line.
21102113
*/
2111-
Terminal.prototype.blankLine = function(cur) {
2114+
Terminal.prototype.blankLine = function(cur, isWrapped) {
21122115
var attr = cur
21132116
? this.eraseAttr()
21142117
: this.defAttr;
@@ -2117,6 +2120,12 @@ Terminal.prototype.blankLine = function(cur) {
21172120
, line = []
21182121
, i = 0;
21192122

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

0 commit comments

Comments
 (0)