diff --git a/src/Linkifier.test.ts b/src/Linkifier.test.ts index 35610acb01..1e4c0cdc8b 100644 --- a/src/Linkifier.test.ts +++ b/src/Linkifier.test.ts @@ -42,6 +42,7 @@ describe('Linkifier', () => { beforeEach(() => { terminal = new MockTerminal(); terminal.cols = 100; + terminal.rows = 10; terminal.buffer = new MockBuffer(); (terminal.buffer).setLines(new CircularList(20)); terminal.buffer.ydisp = 0; @@ -64,6 +65,7 @@ describe('Linkifier', () => { function assertLinkifiesRow(rowText: string, linkMatcherRegex: RegExp, links: {x: number, length: number}[], done: MochaDone): void { addRow(rowText); linkifier.registerLinkMatcher(linkMatcherRegex, () => {}); + terminal.rows = terminal.buffer.lines.length - 1; linkifier.linkifyRows(); // Allow linkify to happen setTimeout(() => { diff --git a/src/Linkifier.ts b/src/Linkifier.ts index 4d84b1a793..0dd33a85cd 100644 --- a/src/Linkifier.ts +++ b/src/Linkifier.ts @@ -81,18 +81,22 @@ export class Linkifier extends EventEmitter implements ILinkifier { */ private _linkifyRows(): void { this._rowsTimeoutId = null; + const buffer = this._terminal.buffer; - // Ensure the row exists - const absoluteRowIndexStart = this._terminal.buffer.ydisp + this._rowsToLinkify.start; - if (absoluteRowIndexStart >= this._terminal.buffer.lines.length) { + // Ensure the start row exists + const absoluteRowIndexStart = buffer.ydisp + this._rowsToLinkify.start; + if (absoluteRowIndexStart >= buffer.lines.length) { return; } + // Invalidate bad end row values (if a resize happened) + const absoluteRowIndexEnd = buffer.ydisp + Math.min(this._rowsToLinkify.end, this._terminal.rows) + 1; + // iterate over the range of unwrapped content strings within start..end (excluding) // _doLinkifyRow gets full unwrapped lines with the start row as buffer offset for every matcher // for wrapped content over several rows the iterator might return rows outside the viewport // we skip those later in _doLinkifyRow - const iterator = this._terminal.buffer.iterator(false, absoluteRowIndexStart, this._terminal.buffer.ydisp + this._rowsToLinkify.end + 1); + const iterator = buffer.iterator(false, absoluteRowIndexStart, absoluteRowIndexEnd); while (iterator.hasNext()) { const lineData: IBufferStringIteratorResult = iterator.next(); for (let i = 0; i < this._linkMatchers.length; i++) {