8000 more verbose comments to get the idea of the code · xtermjs/xterm.js@90ccc81 · GitHub
[go: up one dir, main page]

Skip to content

Commit 90ccc81

Browse files
committed
more verbose comments to get the idea of the code
1 parent 8de7bd5 commit 90ccc81

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/browser/renderer/dom/DomRenderer.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,14 +393,33 @@ export class DomRenderer extends Disposable implements IRenderer {
393393
}
394394

395395
private _setCellUnderline(x: number, x2: number, y: number, y2: number, cols: number, enabled: boolean): void {
396-
const maxY = this._cellToRowElements.length - 1;
396+
/**
397+
* NOTE: The linkifier may send out of viewport y-values if:
398+
* - negative y-value: the link started at a higher line
399+
* - y-value >= maxY: the link ends at a line below viewport
400+
*
401+
* For negative y-values we can simply adjust x = 0,
402+
* as higher up link start means, that everything from
403+
* (0,0) is a link under top-down-left-right char progression
404+
*
405+
* Additionally there might be a small chance of out-of-sync x|y-values
406+
* from a race condition of render updates vs. link event handler execution:
407+
* - (sync) resize: chances terminal buffer in sync, schedules render update async
408+
* - (async) link handler race condition: new buffer metrics, but still on old render state
409+
* - (async) render update: brings term metrics and render state back in sync
410+
*/
397411
if (y < 0) x = 0;
398412
if (y2 < 0) x2 = 0;
413+
414+
// avoid out-of-sync y-values, simply clamp into valid area
415+
const maxY = this._cellToRowElements.length - 1;
399416
y = Math.max(Math.min(y, maxY), 0);
400417
y2 = Math.max(Math.min(y2, maxY), 0);
401418
const elemY = this._cellToRowElements[y];
402419
const elemY2 = this._cellToRowElements[y2];
403420
if (x >= elemY.length || x2 >= elemY2.length) {
421+
// avoid out-of-sync x-values
422+
// simply exit early, gets fixed by the next render update
404423
return;
405424
}
406425
x = elemY[x];

0 commit comments

Comments
 (0)
0