Skip to content

Commit 174a554

Browse files
sreyancoop57
andauthored
fix: render text under block cursor with cursorAccent color (#131)
Block cursors now re-draw the character underneath using the cursorAccent theme color, making text visible on the opaque cursor. Uses ctx.clip() to prevent wide characters from bleeding outside the cursor cell. Co-authored-by: Nathan Cooper <ncoop57@users.noreply.github.com>
1 parent 3525675 commit 174a554

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lib/renderer.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ export class CanvasRenderer {
589589
* Render a cell's text and decorations (Pass 2 of two-pass rendering)
590590
* Selection foreground color is applied here to match the selection background.
591591
*/
592-
private renderCellText(cell: GhosttyCell, x: number, y: number): void {
592+
private renderCellText(cell: GhosttyCell, x: number, y: number, colorOverride?: string): void {
593593
const cellX = x * this.metrics.width;
594594
const cellY = y * this.metrics.height;
595595
const cellWidth = this.metrics.width * cell.width;
@@ -608,8 +608,10 @@ export class CanvasRenderer {
608608
if (cell.flags & CellFlags.BOLD) fontStyle += 'bold ';
609609
this.ctx.font = `${fontStyle}${this.fontSize}px ${this.fontFamily}`;
610610

611-
// Set text color - use selection foreground if selected
612-
if (isSelected) {
611+
// Set text color - use override, selection foreground, or normal color
612+
if (colorOverride) {
613+
this.ctx.fillStyle = colorOverride;
614+
} else if (isSelected) {
613615
this.ctx.fillStyle = this.theme.selectionForeground;
614616
} else {
615617
// Extract colors and handle inverse
@@ -724,6 +726,18 @@ export class CanvasRenderer {
724726
case 'block':
725727
// Full cell block
726728
this.ctx.fillRect(cursorX, cursorY, this.metrics.width, this.metrics.height);
729+
// Re-draw character under cursor with cursorAccent color
730+
{
731+
const line = this.currentBuffer?.getLine(y);
732+
if (line?.[x]) {
733+
this.ctx.save();
734+
this.ctx.beginPath();
735+
this.ctx.rect(cursorX, cursorY, this.metrics.width, this.metrics.height);
736+
this.ctx.clip();
737+
this.renderCellText(line[x], x, y, this.theme.cursorAccent);
738+
this.ctx.restore();
739+
}
740+
}
727741
break;
728742

729743
case 'underline':

0 commit comments

Comments
 (0)