Merge branch 'master' into fix_linkifier_offset
This commit is contained in:
+39
-27
@@ -265,6 +265,7 @@ describe('Buffer', () => {
|
|||||||
const char = String.fromCharCode(code);
|
const char = String.fromCharCode(code);
|
||||||
firstLine.set(i, [null, char, 1, code]);
|
firstLine.set(i, [null, char, 1, code]);
|
||||||
}
|
}
|
||||||
|
buffer.y = 1;
|
||||||
assert.equal(buffer.lines.get(0).length, 5);
|
assert.equal(buffer.lines.get(0).length, 5);
|
||||||
assert.equal(buffer.lines.get(0).translateToString(), 'abcde');
|
assert.equal(buffer.lines.get(0).translateToString(), 'abcde');
|
||||||
buffer.resize(1, 10);
|
buffer.resize(1, 10);
|
||||||
@@ -296,7 +297,7 @@ describe('Buffer', () => {
|
|||||||
buffer.fillViewportRows();
|
buffer.fillViewportRows();
|
||||||
terminal.options.scrollback = 1;
|
terminal.options.scrollback = 1;
|
||||||
buffer.resize(10, 5);
|
buffer.resize(10, 5);
|
||||||
const lastLine = buffer.lines.get(4);
|
const lastLine = buffer.lines.get(3);
|
||||||
for (let i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
const code = 'a'.charCodeAt(0) + i;
|
const code = 'a'.charCodeAt(0) + i;
|
||||||
const char = String.fromCharCode(code);
|
const char = String.fromCharCode(code);
|
||||||
@@ -308,27 +309,27 @@ describe('Buffer', () => {
|
|||||||
assert.equal(buffer.y, 4);
|
assert.equal(buffer.y, 4);
|
||||||
assert.equal(buffer.ybase, 1);
|
assert.equal(buffer.ybase, 1);
|
||||||
assert.equal(buffer.lines.length, 6);
|
assert.equal(buffer.lines.length, 6);
|
||||||
assert.equal(buffer.lines.get(0).translateToString(), ' ');
|
assert.equal(buffer.lines.get(0).translateToString(), 'ab');
|
||||||
assert.equal(buffer.lines.get(1).translateToString(), 'ab');
|
assert.equal(buffer.lines.get(1).translateToString(), 'cd');
|
||||||
assert.equal(buffer.lines.get(2).translateToString(), 'cd');
|
assert.equal(buffer.lines.get(2).translateToString(), 'ef');
|
||||||
assert.equal(buffer.lines.get(3).translateToString(), 'ef');
|
assert.equal(buffer.lines.get(3).translateToString(), 'gh');
|
||||||
assert.equal(buffer.lines.get(4).translateToString(), 'gh');
|
assert.equal(buffer.lines.get(4).translateToString(), 'ij');
|
||||||
assert.equal(buffer.lines.get(5).translateToString(), 'ij');
|
assert.equal(buffer.lines.get(5).translateToString(), ' ');
|
||||||
buffer.resize(1, 5);
|
buffer.resize(1, 5);
|
||||||
assert.equal(buffer.y, 4);
|
assert.equal(buffer.y, 4);
|
||||||
assert.equal(buffer.ybase, 1);
|
assert.equal(buffer.ybase, 1);
|
||||||
assert.equal(buffer.lines.length, 6);
|
assert.equal(buffer.lines.length, 6);
|
||||||
assert.equal(buffer.lines.get(0).translateToString(), 'e');
|
assert.equal(buffer.lines.get(0).translateToString(), 'f');
|
||||||
assert.equal(buffer.lines.get(1).translateToString(), 'f');
|
assert.equal(buffer.lines.get(1).translateToString(), 'g');
|
||||||
assert.equal(buffer.lines.get(2).translateToString(), 'g');
|
assert.equal(buffer.lines.get(2).translateToString(), 'h');
|
||||||
assert.equal(buffer.lines.get(3).translateToString(), 'h');
|
assert.equal(buffer.lines.get(3).translateToString(), 'i');
|
||||||
assert.equal(buffer.lines.get(4).translateToString(), 'i');
|
assert.equal(buffer.lines.get(4).translateToString(), 'j');
|
||||||
assert.equal(buffer.lines.get(5).translateToString(), 'j');
|
assert.equal(buffer.lines.get(5).translateToString(), ' ');
|
||||||
buffer.resize(10, 5);
|
buffer.resize(10, 5);
|
||||||
assert.equal(buffer.y, 0);
|
assert.equal(buffer.y, 1);
|
||||||
assert.equal(buffer.ybase, 0);
|
assert.equal(buffer.ybase, 0);
|
||||||
assert.equal(buffer.lines.length, 5);
|
assert.equal(buffer.lines.length, 5);
|
||||||
assert.equal(buffer.lines.get(0).translateToString(), 'efghij ');
|
assert.equal(buffer.lines.get(0).translateToString(), 'fghij ');
|
||||||
assert.equal(buffer.lines.get(1).translateToString(), ' ');
|
assert.equal(buffer.lines.get(1).translateToString(), ' ');
|
||||||
assert.equal(buffer.lines.get(2).translateToString(), ' ');
|
assert.equal(buffer.lines.get(2).translateToString(), ' ');
|
||||||
assert.equal(buffer.lines.get(3).translateToString(), ' ');
|
assert.equal(buffer.lines.get(3).translateToString(), ' ');
|
||||||
@@ -339,6 +340,7 @@ describe('Buffer', () => {
|
|||||||
// 3+ lines removed on a reflow actually remove the right lines
|
// 3+ lines removed on a reflow actually remove the right lines
|
||||||
buffer.fillViewportRows();
|
buffer.fillViewportRows();
|
||||||
buffer.resize(10, 10);
|
buffer.resize(10, 10);
|
||||||
|
buffer.y = 2;
|
||||||
const firstLine = buffer.lines.get(0);
|
const firstLine = buffer.lines.get(0);
|
||||||
const secondLine = buffer.lines.get(1);
|
const secondLine = buffer.lines.get(1);
|
||||||
for (let i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
@@ -358,8 +360,8 @@ describe('Buffer', () => {
|
|||||||
assert.equal(buffer.lines.get(i).translateToString(), ' ');
|
assert.equal(buffer.lines.get(i).translateToString(), ' ');
|
||||||
}
|
}
|
||||||
buffer.resize(2, 10);
|
buffer.resize(2, 10);
|
||||||
assert.equal(buffer.ybase, 0);
|
assert.equal(buffer.ybase, 1);
|
||||||
assert.equal(buffer.lines.length, 10);
|
assert.equal(buffer.lines.length, 11);
|
||||||
assert.equal(buffer.lines.get(0).translateToString(), 'ab');
|
assert.equal(buffer.lines.get(0).translateToString(), 'ab');
|
||||||
assert.equal(buffer.lines.get(1).translateToString(), 'cd');
|
assert.equal(buffer.lines.get(1).translateToString(), 'cd');
|
||||||
assert.equal(buffer.lines.get(2).translateToString(), 'ef');
|
assert.equal(buffer.lines.get(2).translateToString(), 'ef');
|
||||||
@@ -370,7 +372,10 @@ describe('Buffer', () => {
|
|||||||
assert.equal(buffer.lines.get(7).translateToString(), '45');
|
assert.equal(buffer.lines.get(7).translateToString(), '45');
|
||||||
assert.equal(buffer.lines.get(8).translateToString(), '67');
|
assert.equal(buffer.lines.get(8).translateToString(), '67');
|
||||||
assert.equal(buffer.lines.get(9).translateToString(), '89');
|
assert.equal(buffer.lines.get(9).translateToString(), '89');
|
||||||
|
assert.equal(buffer.lines.get(10).translateToString(), ' ');
|
||||||
buffer.resize(10, 10);
|
buffer.resize(10, 10);
|
||||||
|
assert.equal(buffer.ybase, 0);
|
||||||
|
assert.equal(buffer.lines.length, 10);
|
||||||
assert.equal(buffer.lines.get(0).translateToString(), 'abcdefghij');
|
assert.equal(buffer.lines.get(0).translateToString(), 'abcdefghij');
|
||||||
assert.equal(buffer.lines.get(1).translateToString(), '0123456789');
|
assert.equal(buffer.lines.get(1).translateToString(), '0123456789');
|
||||||
for (let i = 2; i < 10; i++) {
|
for (let i = 2; i < 10; i++) {
|
||||||
@@ -379,22 +384,23 @@ describe('Buffer', () => {
|
|||||||
});
|
});
|
||||||
it('should transfer combined char data over to reflowed lines', () => {
|
it('should transfer combined char data over to reflowed lines', () => {
|
||||||
buffer.fillViewportRows();
|
buffer.fillViewportRows();
|
||||||
buffer.resize(4, 2);
|
buffer.resize(4, 3);
|
||||||
|
buffer.y = 2;
|
||||||
const firstLine = buffer.lines.get(0);
|
const firstLine = buffer.lines.get(0);
|
||||||
firstLine.set(0, [ null, 'a', 1, 'a'.charCodeAt(0) ]);
|
firstLine.set(0, [ null, 'a', 1, 'a'.charCodeAt(0) ]);
|
||||||
firstLine.set(1, [ null, 'b', 1, 'b'.charCodeAt(0) ]);
|
firstLine.set(1, [ null, 'b', 1, 'b'.charCodeAt(0) ]);
|
||||||
firstLine.set(2, [ null, 'c', 1, 'c'.charCodeAt(0) ]);
|
firstLine.set(2, [ null, 'c', 1, 'c'.charCodeAt(0) ]);
|
||||||
firstLine.set(3, [ null, '😁', 1, '😁'.charCodeAt(0) ]);
|
firstLine.set(3, [ null, '😁', 1, '😁'.charCodeAt(0) ]);
|
||||||
assert.equal(buffer.lines.length, 2);
|
assert.equal(buffer.lines.length, 3);
|
||||||
assert.equal(buffer.lines.get(0).translateToString(), 'abc😁');
|
assert.equal(buffer.lines.get(0).translateToString(), 'abc😁');
|
||||||
assert.equal(buffer.lines.get(1).translateToString(), ' ');
|
assert.equal(buffer.lines.get(1).translateToString(), ' ');
|
||||||
buffer.resize(2, 2);
|
buffer.resize(2, 3);
|
||||||
assert.equal(buffer.lines.get(0).translateToString(), 'ab');
|
assert.equal(buffer.lines.get(0).translateToString(), 'ab');
|
||||||
assert.equal(buffer.lines.get(1).translateToString(), 'c😁');
|
assert.equal(buffer.lines.get(1).translateToString(), 'c😁');
|
||||||
});
|
});
|
||||||
it('should adjust markers when reflowing', () => {
|
it('should adjust markers when reflowing', () => {
|
||||||
buffer.fillViewportRows();
|
buffer.fillViewportRows();
|
||||||
buffer.resize(10, 15);
|
buffer.resize(10, 16);
|
||||||
for (let i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
const code = 'a'.charCodeAt(0) + i;
|
const code = 'a'.charCodeAt(0) + i;
|
||||||
const char = String.fromCharCode(code);
|
const char = String.fromCharCode(code);
|
||||||
@@ -410,6 +416,7 @@ describe('Buffer', () => {
|
|||||||
const char = String.fromCharCode(code);
|
const char = String.fromCharCode(code);
|
||||||
buffer.lines.get(2).set(i, [null, char, 1, code]);
|
buffer.lines.get(2).set(i, [null, char, 1, code]);
|
||||||
}
|
}
|
||||||
|
buffer.y = 3;
|
||||||
// Buffer:
|
// Buffer:
|
||||||
// abcdefghij
|
// abcdefghij
|
||||||
// 0123456789
|
// 0123456789
|
||||||
@@ -423,7 +430,7 @@ describe('Buffer', () => {
|
|||||||
assert.equal(firstMarker.line, 0);
|
assert.equal(firstMarker.line, 0);
|
||||||
assert.equal(secondMarker.line, 1);
|
assert.equal(secondMarker.line, 1);
|
||||||
assert.equal(thirdMarker.line, 2);
|
assert.equal(thirdMarker.line, 2);
|
||||||
buffer.resize(2, 15);
|
buffer.resize(2, 16);
|
||||||
assert.equal(buffer.lines.get(0).translateToString(), 'ab');
|
assert.equal(buffer.lines.get(0).translateToString(), 'ab');
|
||||||
assert.equal(buffer.lines.get(1).translateToString(), 'cd');
|
assert.equal(buffer.lines.get(1).translateToString(), 'cd');
|
||||||
assert.equal(buffer.lines.get(2).translateToString(), 'ef');
|
assert.equal(buffer.lines.get(2).translateToString(), 'ef');
|
||||||
@@ -442,7 +449,7 @@ describe('Buffer', () => {
|
|||||||
assert.equal(firstMarker.line, 0, 'first marker should remain unchanged');
|
assert.equal(firstMarker.line, 0, 'first marker should remain unchanged');
|
||||||
assert.equal(secondMarker.line, 5, 'second marker should be shifted since the first line wrapped');
|
assert.equal(secondMarker.line, 5, 'second marker should be shifted since the first line wrapped');
|
||||||
assert.equal(thirdMarker.line, 10, 'third marker should be shifted since the first and second lines wrapped');
|
assert.equal(thirdMarker.line, 10, 'third marker should be shifted since the first and second lines wrapped');
|
||||||
buffer.resize(10, 15);
|
buffer.resize(10, 16);
|
||||||
assert.equal(buffer.lines.get(0).translateToString(), 'abcdefghij');
|
assert.equal(buffer.lines.get(0).translateToString(), 'abcdefghij');
|
||||||
assert.equal(buffer.lines.get(1).translateToString(), '0123456789');
|
assert.equal(buffer.lines.get(1).translateToString(), '0123456789');
|
||||||
assert.equal(buffer.lines.get(2).translateToString(), 'klmnopqrst');
|
assert.equal(buffer.lines.get(2).translateToString(), 'klmnopqrst');
|
||||||
@@ -456,7 +463,7 @@ describe('Buffer', () => {
|
|||||||
it('should dispose markers whose rows are trimmed during a reflow', () => {
|
it('should dispose markers whose rows are trimmed during a reflow', () => {
|
||||||
buffer.fillViewportRows();
|
buffer.fillViewportRows();
|
||||||
terminal.options.scrollback = 1;
|
terminal.options.scrollback = 1;
|
||||||
buffer.resize(10, 10);
|
buffer.resize(10, 11);
|
||||||
for (let i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
const code = 'a'.charCodeAt(0) + i;
|
const code = 'a'.charCodeAt(0) + i;
|
||||||
const char = String.fromCharCode(code);
|
const char = String.fromCharCode(code);
|
||||||
@@ -472,6 +479,7 @@ describe('Buffer', () => {
|
|||||||
const char = String.fromCharCode(code);
|
const char = String.fromCharCode(code);
|
||||||
buffer.lines.get(2).set(i, [null, char, 1, code]);
|
buffer.lines.get(2).set(i, [null, char, 1, code]);
|
||||||
}
|
}
|
||||||
|
buffer.y = 10;
|
||||||
// Buffer:
|
// Buffer:
|
||||||
// abcdefghij
|
// abcdefghij
|
||||||
// 0123456789
|
// 0123456789
|
||||||
@@ -479,14 +487,14 @@ describe('Buffer', () => {
|
|||||||
const firstMarker = buffer.addMarker(0);
|
const firstMarker = buffer.addMarker(0);
|
||||||
const secondMarker = buffer.addMarker(1);
|
const secondMarker = buffer.addMarker(1);
|
||||||
const thirdMarker = buffer.addMarker(2);
|
const thirdMarker = buffer.addMarker(2);
|
||||||
buffer.y = 2;
|
buffer.y = 3;
|
||||||
assert.equal(buffer.lines.get(0).translateToString(), 'abcdefghij');
|
assert.equal(buffer.lines.get(0).translateToString(), 'abcdefghij');
|
||||||
assert.equal(buffer.lines.get(1).translateToString(), '0123456789');
|
assert.equal(buffer.lines.get(1).translateToString(), '0123456789');
|
||||||
assert.equal(buffer.lines.get(2).translateToString(), 'klmnopqrst');
|
assert.equal(buffer.lines.get(2).translateToString(), 'klmnopqrst');
|
||||||
assert.equal(firstMarker.line, 0);
|
assert.equal(firstMarker.line, 0);
|
||||||
assert.equal(secondMarker.line, 1);
|
assert.equal(secondMarker.line, 1);
|
||||||
assert.equal(thirdMarker.line, 2);
|
assert.equal(thirdMarker.line, 2);
|
||||||
buffer.resize(2, 10);
|
buffer.resize(2, 11);
|
||||||
assert.equal(buffer.lines.get(0).translateToString(), 'ij');
|
assert.equal(buffer.lines.get(0).translateToString(), 'ij');
|
||||||
assert.equal(buffer.lines.get(1).translateToString(), '01');
|
assert.equal(buffer.lines.get(1).translateToString(), '01');
|
||||||
assert.equal(buffer.lines.get(2).translateToString(), '23');
|
assert.equal(buffer.lines.get(2).translateToString(), '23');
|
||||||
@@ -503,7 +511,7 @@ describe('Buffer', () => {
|
|||||||
assert.equal(firstMarker.isDisposed, true, 'first marker was trimmed');
|
assert.equal(firstMarker.isDisposed, true, 'first marker was trimmed');
|
||||||
assert.equal(secondMarker.isDisposed, false);
|
assert.equal(secondMarker.isDisposed, false);
|
||||||
assert.equal(thirdMarker.isDisposed, false);
|
assert.equal(thirdMarker.isDisposed, false);
|
||||||
buffer.resize(10, 10);
|
buffer.resize(10, 11);
|
||||||
assert.equal(buffer.lines.get(0).translateToString(), 'ij ');
|
assert.equal(buffer.lines.get(0).translateToString(), 'ij ');
|
||||||
assert.equal(buffer.lines.get(1).translateToString(), '0123456789');
|
assert.equal(buffer.lines.get(1).translateToString(), '0123456789');
|
||||||
assert.equal(buffer.lines.get(2).translateToString(), 'klmnopqrst');
|
assert.equal(buffer.lines.get(2).translateToString(), 'klmnopqrst');
|
||||||
@@ -513,6 +521,7 @@ describe('Buffer', () => {
|
|||||||
it('should wrap wide characters correctly when reflowing larger', () => {
|
it('should wrap wide characters correctly when reflowing larger', () => {
|
||||||
buffer.fillViewportRows();
|
buffer.fillViewportRows();
|
||||||
buffer.resize(12, 10);
|
buffer.resize(12, 10);
|
||||||
|
buffer.y = 2;
|
||||||
for (let i = 0; i < 12; i += 4) {
|
for (let i = 0; i < 12; i += 4) {
|
||||||
buffer.lines.get(0).set(i, [null, '汉', 2, '汉'.charCodeAt(0)]);
|
buffer.lines.get(0).set(i, [null, '汉', 2, '汉'.charCodeAt(0)]);
|
||||||
buffer.lines.get(1).set(i, [null, '汉', 2, '汉'.charCodeAt(0)]);
|
buffer.lines.get(1).set(i, [null, '汉', 2, '汉'.charCodeAt(0)]);
|
||||||
@@ -547,6 +556,7 @@ describe('Buffer', () => {
|
|||||||
it('should wrap wide characters correctly when reflowing smaller', () => {
|
it('should wrap wide characters correctly when reflowing smaller', () => {
|
||||||
buffer.fillViewportRows();
|
buffer.fillViewportRows();
|
||||||
buffer.resize(12, 10);
|
buffer.resize(12, 10);
|
||||||
|
buffer.y = 2;
|
||||||
for (let i = 0; i < 12; i += 4) {
|
for (let i = 0; i < 12; i += 4) {
|
||||||
buffer.lines.get(0).set(i, [null, '汉', 2, '汉'.charCodeAt(0)]);
|
buffer.lines.get(0).set(i, [null, '汉', 2, '汉'.charCodeAt(0)]);
|
||||||
buffer.lines.get(1).set(i, [null, '汉', 2, '汉'.charCodeAt(0)]);
|
buffer.lines.get(1).set(i, [null, '汉', 2, '汉'.charCodeAt(0)]);
|
||||||
@@ -937,6 +947,7 @@ describe('Buffer', () => {
|
|||||||
describe('&& ydisp === ybase', () => {
|
describe('&& ydisp === ybase', () => {
|
||||||
it('should trim lines and keep ydisp = ybase', () => {
|
it('should trim lines and keep ydisp = ybase', () => {
|
||||||
buffer.ydisp = 10;
|
buffer.ydisp = 10;
|
||||||
|
buffer.y = 13;
|
||||||
buffer.resize(2, 10);
|
buffer.resize(2, 10);
|
||||||
assert.equal(buffer.ydisp, 10);
|
assert.equal(buffer.ydisp, 10);
|
||||||
assert.equal(buffer.ybase, 10);
|
assert.equal(buffer.ybase, 10);
|
||||||
@@ -962,6 +973,7 @@ describe('Buffer', () => {
|
|||||||
describe('&& ydisp !== ybase', () => {
|
describe('&& ydisp !== ybase', () => {
|
||||||
it('should trim lines and not change ydisp', () => {
|
it('should trim lines and not change ydisp', () => {
|
||||||
buffer.ydisp = 5;
|
buffer.ydisp = 5;
|
||||||
|
buffer.y = 13;
|
||||||
buffer.resize(2, 10);
|
buffer.resize(2, 10);
|
||||||
assert.equal(buffer.ydisp, 5);
|
assert.equal(buffer.ydisp, 5);
|
||||||
assert.equal(buffer.ybase, 10);
|
assert.equal(buffer.ybase, 10);
|
||||||
|
|||||||
+29
-15
@@ -3,13 +3,13 @@
|
|||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { CircularList, IInsertEvent, IDeleteEvent } from './common/CircularList';
|
|
||||||
import { CharData, ITerminal, IBuffer, IBufferLine, BufferIndex, IBufferStringIterator, IBufferStringIteratorResult } from './Types';
|
|
||||||
import { EventEmitter } from './common/EventEmitter';
|
|
||||||
import { IMarker } from 'xterm';
|
import { IMarker } from 'xterm';
|
||||||
import { BufferLine } from './BufferLine';
|
import { BufferLine } from './BufferLine';
|
||||||
|
import { reflowLargerApplyNewLayout, reflowLargerCreateNewLayout, reflowLargerGetLinesToRemove, reflowSmallerGetNewLineLengths } from './BufferReflow';
|
||||||
|
import { CircularList, IDeleteEvent, IInsertEvent } from './common/CircularList';
|
||||||
|
import { EventEmitter } from './common/EventEmitter';
|
||||||
import { DEFAULT_COLOR } from './renderer/atlas/Types';
|
import { DEFAULT_COLOR } from './renderer/atlas/Types';
|
||||||
import { reflowSmallerGetNewLineLengths, reflowLargerGetLinesToRemove, reflowLargerCreateNewLayout, reflowLargerApplyNewLayout } from './BufferReflow';
|
import { BufferIndex, CharData, IBuffer, IBufferLine, IBufferStringIterator, IBufferStringIteratorResult, ITerminal } from './Types';
|
||||||
|
|
||||||
export const DEFAULT_ATTR = (0 << 18) | (DEFAULT_COLOR << 9) | (256 << 0);
|
export const DEFAULT_ATTR = (0 << 18) | (DEFAULT_COLOR << 9) | (256 << 0);
|
||||||
export const CHAR_DATA_ATTR_INDEX = 0;
|
export const CHAR_DATA_ATTR_INDEX = 0;
|
||||||
@@ -212,7 +212,7 @@ export class Buffer implements IBuffer {
|
|||||||
this.scrollBottom = newRows - 1;
|
this.scrollBottom = newRows - 1;
|
||||||
|
|
||||||
if (this._hasScrollback) {
|
if (this._hasScrollback) {
|
||||||
this._reflow(newCols);
|
this._reflow(newCols, newRows);
|
||||||
|
|
||||||
// Trim the end of the line off if cols shrunk
|
// Trim the end of the line off if cols shrunk
|
||||||
if (this._cols > newCols) {
|
if (this._cols > newCols) {
|
||||||
@@ -226,7 +226,7 @@ export class Buffer implements IBuffer {
|
|||||||
this._rows = newRows;
|
this._rows = newRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _reflow(newCols: number): void {
|
private _reflow(newCols: number, newRows: number): void {
|
||||||
if (this._cols === newCols) {
|
if (this._cols === newCols) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -235,12 +235,12 @@ export class Buffer implements IBuffer {
|
|||||||
if (newCols > this._cols) {
|
if (newCols > this._cols) {
|
||||||
this._reflowLarger(newCols);
|
this._reflowLarger(newCols);
|
||||||
} else {
|
} else {
|
||||||
this._reflowSmaller(newCols);
|
this._reflowSmaller(newCols, newRows);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _reflowLarger(newCols: number): void {
|
private _reflowLarger(newCols: number): void {
|
||||||
const toRemove: number[] = reflowLargerGetLinesToRemove(this.lines, newCols);
|
const toRemove: number[] = reflowLargerGetLinesToRemove(this.lines, newCols, this.ybase + this.y);
|
||||||
if (toRemove.length > 0) {
|
if (toRemove.length > 0) {
|
||||||
const newLayoutResult = reflowLargerCreateNewLayout(this.lines, toRemove);
|
const newLayoutResult = reflowLargerCreateNewLayout(this.lines, toRemove);
|
||||||
reflowLargerApplyNewLayout(this.lines, newLayoutResult.layout);
|
reflowLargerApplyNewLayout(this.lines, newLayoutResult.layout);
|
||||||
@@ -253,9 +253,13 @@ export class Buffer implements IBuffer {
|
|||||||
let viewportAdjustments = countRemoved;
|
let viewportAdjustments = countRemoved;
|
||||||
while (viewportAdjustments-- > 0) {
|
while (viewportAdjustments-- > 0) {
|
||||||
if (this.ybase === 0) {
|
if (this.ybase === 0) {
|
||||||
this.y--;
|
if (this.y > 0) {
|
||||||
// Add an extra row at the bottom of the viewport
|
this.y--;
|
||||||
this.lines.push(new BufferLine(newCols, FILL_CHAR_DATA));
|
}
|
||||||
|
if (this.lines.length < this._rows) {
|
||||||
|
// Add an extra row at the bottom of the viewport
|
||||||
|
this.lines.push(new BufferLine(newCols, FILL_CHAR_DATA));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.ydisp === this.ybase) {
|
if (this.ydisp === this.ybase) {
|
||||||
this.ydisp--;
|
this.ydisp--;
|
||||||
@@ -265,7 +269,7 @@ export class Buffer implements IBuffer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _reflowSmaller(newCols: number): void {
|
private _reflowSmaller(newCols: number, newRows: number): void {
|
||||||
// Gather all BufferLines that need to be inserted into the Buffer here so that they can be
|
// Gather all BufferLines that need to be inserted into the Buffer here so that they can be
|
||||||
// batched up and only committed once
|
// batched up and only committed once
|
||||||
const toInsert = [];
|
const toInsert = [];
|
||||||
@@ -285,6 +289,13 @@ export class Buffer implements IBuffer {
|
|||||||
wrappedLines.unshift(nextLine);
|
wrappedLines.unshift(nextLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If these lines contain the cursor don't touch them, the program will handle fixing up
|
||||||
|
// wrapped lines with the cursor
|
||||||
|
const absoluteY = this.ybase + this.y;
|
||||||
|
if (absoluteY >= y && absoluteY < y + wrappedLines.length) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const lastLineLength = wrappedLines[wrappedLines.length - 1].getTrimmedLength();
|
const lastLineLength = wrappedLines[wrappedLines.length - 1].getTrimmedLength();
|
||||||
const destLineLengths = reflowSmallerGetNewLineLengths(wrappedLines, this._cols, newCols);
|
const destLineLengths = reflowSmallerGetNewLineLengths(wrappedLines, this._cols, newCols);
|
||||||
const linesToAdd = destLineLengths.length - wrappedLines.length;
|
const linesToAdd = destLineLengths.length - wrappedLines.length;
|
||||||
@@ -357,10 +368,13 @@ export class Buffer implements IBuffer {
|
|||||||
this.ydisp++;
|
this.ydisp++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.ybase === this.ydisp) {
|
// Ensure ybase does not exceed its maximum value
|
||||||
this.ydisp++;
|
if (this.ybase < Math.min(this.lines.maxLength, this.lines.length + countToInsert) - newRows) {
|
||||||
|
if (this.ybase === this.ydisp) {
|
||||||
|
this.ydisp++;
|
||||||
|
}
|
||||||
|
this.ybase++;
|
||||||
}
|
}
|
||||||
this.ybase++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-4
@@ -3,10 +3,10 @@
|
|||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { FILL_CHAR_DATA } from './Buffer';
|
||||||
import { BufferLine } from './BufferLine';
|
import { BufferLine } from './BufferLine';
|
||||||
import { CircularList, IDeleteEvent } from './common/CircularList';
|
import { CircularList, IDeleteEvent } from './common/CircularList';
|
||||||
import { IBufferLine } from './Types';
|
import { IBufferLine } from './Types';
|
||||||
import { FILL_CHAR_DATA } from './Buffer';
|
|
||||||
|
|
||||||
export interface INewLayoutResult {
|
export interface INewLayoutResult {
|
||||||
layout: number[];
|
layout: number[];
|
||||||
@@ -19,7 +19,7 @@ export interface INewLayoutResult {
|
|||||||
* @param lines The buffer lines.
|
* @param lines The buffer lines.
|
||||||
* @param newCols The columns after resize.
|
* @param newCols The columns after resize.
|
||||||
*/
|
*/
|
||||||
export function reflowLargerGetLinesToRemove(lines: CircularList<IBufferLine>, newCols: number): number[] {
|
export function reflowLargerGetLinesToRemove(lines: CircularList<IBufferLine>, newCols: number, bufferAbsoluteY: number): number[] {
|
||||||
// Gather all BufferLines that need to be removed from the Buffer here so that they can be
|
// Gather all BufferLines that need to be removed from the Buffer here so that they can be
|
||||||
// batched up and only committed once
|
// batched up and only committed once
|
||||||
const toRemove: number[] = [];
|
const toRemove: number[] = [];
|
||||||
@@ -39,6 +39,13 @@ export function reflowLargerGetLinesToRemove(lines: CircularList<IBufferLine>, n
|
|||||||
nextLine = lines.get(++i) as BufferLine;
|
nextLine = lines.get(++i) as BufferLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If these lines contain the cursor don't touch them, the program will handle fixing up wrapped
|
||||||
|
// lines with the cursor
|
||||||
|
if (bufferAbsoluteY >= y && bufferAbsoluteY < i) {
|
||||||
|
y += wrappedLines.length - 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Copy buffer data to new locations
|
// Copy buffer data to new locations
|
||||||
let destLineIndex = 0;
|
let destLineIndex = 0;
|
||||||
let destCol = wrappedLines[destLineIndex].getTrimmedLength();
|
let destCol = wrappedLines[destLineIndex].getTrimmedLength();
|
||||||
@@ -64,7 +71,7 @@ export function reflowLargerGetLinesToRemove(lines: CircularList<IBufferLine>, n
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the last cell isn't wide, if it is copy it to the current dest
|
// Make sure the last cell isn't wide, if it is copy it to the current dest
|
||||||
if (destCol === 0) {
|
if (destCol === 0 && destLineIndex !== 0) {
|
||||||
if (wrappedLines[destLineIndex - 1].getWidth(newCols - 1) === 2) {
|
if (wrappedLines[destLineIndex - 1].getWidth(newCols - 1) === 2) {
|
||||||
wrappedLines[destLineIndex].copyCellsFrom(wrappedLines[destLineIndex - 1], newCols - 1, destCol++, 1, false);
|
wrappedLines[destLineIndex].copyCellsFrom(wrappedLines[destLineIndex - 1], newCols - 1, destCol++, 1, false);
|
||||||
// Null out the end of the last row
|
// Null out the end of the last row
|
||||||
@@ -166,7 +173,6 @@ export function reflowLargerApplyNewLayout(lines: CircularList<IBufferLine>, new
|
|||||||
*/
|
*/
|
||||||
export function reflowSmallerGetNewLineLengths(wrappedLines: BufferLine[], oldCols: number, newCols: number): number[] {
|
export function reflowSmallerGetNewLineLengths(wrappedLines: BufferLine[], oldCols: number, newCols: number): number[] {
|
||||||
const newLineLengths: number[] = [];
|
const newLineLengths: number[] = [];
|
||||||
|
|
||||||
const cellsNeeded = wrappedLines.map(l => l.getTrimmedLength()).reduce((p, c) => p + c);
|
const cellsNeeded = wrappedLines.map(l => l.getTrimmedLength()).reduce((p, c) => p + c);
|
||||||
|
|
||||||
// Use srcCol and srcLine to find the new wrapping point, use that to get the cellsAvailable and
|
// Use srcCol and srcLine to find the new wrapping point, use that to get the cellsAvailable and
|
||||||
|
|||||||
Reference in New Issue
Block a user