Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webgl cursor renderer makes sure a char is not drawn outside of the cell #4102

Merged
merged 1 commit into from
Sep 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions addons/xterm-addon-webgl/src/renderLayer/BaseRenderLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,24 +226,25 @@ export abstract class BaseRenderLayer implements IRenderLayer {
protected _fillCharTrueColor(terminal: Terminal, cell: CellData, x: number, y: number): void {
this._ctx.font = this._getFont(terminal, false, false);
this._ctx.textBaseline = TEXT_BASELINE;
this._clipRow(terminal, y);
this._clipCell(x, y, cell.getWidth());
this._ctx.fillText(
cell.getChars(),
x * this._scaledCellWidth + this._scaledCharLeft,
y * this._scaledCellHeight + this._scaledCharTop + this._scaledCharHeight);
}

/**
* Clips a row to ensure no pixels will be drawn outside the cells in the row.
* @param terminal The terminal.
* Clips a cell to ensure no pixels will be drawn outside of it.
* @param x The column to clip.
* @param y The row to clip.
* @param width The number of columns to clip.
*/
private _clipRow(terminal: Terminal, y: number): void {
private _clipCell(x: number, y: number, width: number): void {
this._ctx.beginPath();
this._ctx.rect(
0,
x * this._scaledCellWidth,
y * this._scaledCellHeight,
terminal.cols * this._scaledCellWidth,
width * this._scaledCellWidth,
this._scaledCellHeight);
this._ctx.clip();
}
Expand Down