Skip to content

Commit 2e8e64e

Browse files
authored
Merge pull request #1703 from Tyriar/1702_isWrapped_fix
Speculative fix for NPE in linkifier
2 parents 290c95a + 2c62c3a commit 2e8e64e

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/Linkifier.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ describe('Linkifier', () => {
4242
beforeEach(() => {
4343
terminal = new MockTerminal();
4444
terminal.cols = 100;
45+
terminal.rows = 10;
4546
terminal.buffer = new MockBuffer();
4647
(<MockBuffer>terminal.buffer).setLines(new CircularList<IBufferLine>(20));
4748
terminal.buffer.ydisp = 0;
@@ -64,6 +65,7 @@ describe('Linkifier', () => {
6465
function assertLinkifiesRow(rowText: string, linkMatcherRegex: RegExp, links: {x: number, length: number}[], done: MochaDone): void {
6566
addRow(rowText);
6667
linkifier.registerLinkMatcher(linkMatcherRegex, () => {});
68+
terminal.rows = terminal.buffer.lines.length - 1;
6769
linkifier.linkifyRows();
6870
// Allow linkify to happen
6971
setTimeout(() => {

src/Linkifier.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,22 @@ export class Linkifier extends EventEmitter implements ILinkifier {
8181
*/
8282
private _linkifyRows(): void {
8383
this._rowsTimeoutId = null;
84+
const buffer = this._terminal.buffer;
8485

85-
// Ensure the row exists
86-
const absoluteRowIndexStart = this._terminal.buffer.ydisp + this._rowsToLinkify.start;
87-
if (absoluteRowIndexStart >= this._terminal.buffer.lines.length) {
86+
// Ensure the start row exists
87+
const absoluteRowIndexStart = buffer.ydisp + this._rowsToLinkify.start;
88+
if (absoluteRowIndexStart >= buffer.lines.length) {
8889
return;
8990
}
9091

92+
// Invalidate bad end row values (if a resize happened)
93+
const absoluteRowIndexEnd = buffer.ydisp + Math.min(this._rowsToLinkify.end, this._terminal.rows) + 1;
94+
9195
// iterate over the range of unwrapped content strings within start..end (excluding)
9296
// _doLinkifyRow gets full unwrapped lines with the start row as buffer offset for every matcher
9397
// for wrapped content over several rows the iterator might return rows outside the viewport
9498
// we skip those later in _doLinkifyRow
95-
const iterator = this._terminal.buffer.iterator(false, absoluteRowIndexStart, this._terminal.buffer.ydisp + this._rowsToLinkify.end + 1);
99+
const iterator = buffer.iterator(false, absoluteRowIndexStart, absoluteRowIndexEnd);
96100
while (iterator.hasNext()) {
97101
const lineData: IBufferStringIteratorResult = iterator.next();
98102
for (let i = 0; i < this._linkMatchers.length; i++) {

0 commit comments

Comments
 (0)