Skip to content

Commit ee0e944

Browse files
slang25claude
andcommitted
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>
1 parent 03ead6e commit ee0e944

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

lib/renderer.ts

Lines changed: 11 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
@@ -790,6 +794,7 @@ export class CanvasRenderer {
790794
this.theme.brightCyan,
791795
this.theme.brightWhite,
792796
];
797+
793798
}
794799

795800
/**
@@ -854,6 +859,7 @@ export class CanvasRenderer {
854859
const scrollbarTrackHeight = canvasHeight - scrollbarPadding * 2;
855860

856861
// Always clear the scrollbar area first (fixes ghosting when fading out)
862+
ctx.clearRect(scrollbarX - 2, 0, scrollbarWidth + 6, canvasHeight);
857863
ctx.fillStyle = this.theme.background;
858864
ctx.fillRect(scrollbarX - 2, 0, scrollbarWidth + 6, canvasHeight);
859865

@@ -966,6 +972,9 @@ export class CanvasRenderer {
966972
* Clear entire canvas
967973
*/
968974
public clear(): void {
975+
// clearRect first because fillRect composites rather than replaces,
976+
// so transparent/translucent backgrounds wouldn't clear previous content.
977+
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
969978
this.ctx.fillStyle = this.theme.background;
970979
this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
971980
}

0 commit comments

Comments
 (0)