Skip to content

Commit 77e29d9

Browse files
slang25claude
andauthored
fix: clear canvas before filling to support transparent backgrounds (#116)
* fix: clear canvas before filling to support transparent backgrounds When using a transparent background color, fillRect composites rather than replaces pixels. Add clearRect before fillRect in renderLine, clear, and renderScrollbar to properly erase previous content before applying the background color. This fixes content piling up when using transparent backgrounds and ensures selection highlighting clears properly. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> * style: remove extra blank line Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
1 parent 03ead6e commit 77e29d9

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

lib/renderer.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,12 +515,16 @@ export class CanvasRenderer {
515515
*/
516516
private renderLine(line: GhosttyCell[], y: number, cols: number): void {
517517
const lineY = y * this.metrics.height;
518+
const lineWidth = cols * this.metrics.width;
518519

519-
// Clear line background with theme color.
520+
// Clear line background then fill with theme color.
520521
// We clear just the cell area - glyph overflow is handled by also
521522
// redrawing adjacent rows (see render() method).
523+
// clearRect is needed because fillRect composites rather than replaces,
524+
// so transparent/translucent backgrounds wouldn't clear previous content.
525+
this.ctx.clearRect(0, lineY, lineWidth, this.metrics.height);
522526
this.ctx.fillStyle = this.theme.background;
523-
this.ctx.fillRect(0, lineY, cols * this.metrics.width, this.metrics.height);
527+
this.ctx.fillRect(0, lineY, lineWidth, this.metrics.height);
524528

525529
// PASS 1: Draw all cell backgrounds first
526530
// This ensures all backgrounds are painted before any text, allowing text
@@ -854,6 +858,7 @@ export class CanvasRenderer {
854858
const scrollbarTrackHeight = canvasHeight - scrollbarPadding * 2;
855859

856860
// Always clear the scrollbar area first (fixes ghosting when fading out)
861+
ctx.clearRect(scrollbarX - 2, 0, scrollbarWidth + 6, canvasHeight);
857862
ctx.fillStyle = this.theme.background;
858863
ctx.fillRect(scrollbarX - 2, 0, scrollbarWidth + 6, canvasHeight);
859864

@@ -966,6 +971,9 @@ export class CanvasRenderer {
966971
* Clear entire canvas
967972
*/
968973
public clear(): void {
974+
// clearRect first because fillRect composites rather than replaces,
975+
// so transparent/translucent backgrounds wouldn't clear previous content.
976+
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
969977
this.ctx.fillStyle = this.theme.background;
970978
this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
971979
}

0 commit comments

Comments
 (0)