@@ -47,14 +47,15 @@ function fillSolidPowerlineSeparator(
4747 text : string ,
4848 left : number ,
4949 top : number ,
50- metrics : GhosttyCellMetrics ,
50+ width : number ,
51+ height : number ,
5152) : void {
52- const right = left + metrics . width ;
53+ const right = left + width ;
5354 const [ base , point ] = text === POWERLINE_SOLID_RIGHT ? [ left , right ] : [ right , left ] ;
5455 context . beginPath ( ) ;
5556 context . moveTo ( base , top ) ;
56- context . lineTo ( point , top + metrics . height / 2 ) ;
57- context . lineTo ( base , top + metrics . height ) ;
57+ context . lineTo ( point , top + height / 2 ) ;
58+ context . lineTo ( base , top + height ) ;
5859 context . closePath ( ) ;
5960 context . fill ( ) ;
6061}
@@ -145,6 +146,12 @@ export function renderGhosttySnapshot(options: {
145146 const selectionBackground = options . selectionBackground ?? DEFAULT_SELECTION_BACKGROUND ;
146147 const hoveredLinkRange = options . hoveredLinkRange ?? null ;
147148 const originY = options . originY ?? padding ;
149+ // Rows start on whole device pixels and clear the full canvas width, so repainting
150+ // a row replaces every pixel the last frame drew in it, including a cursor's edges.
151+ const transform = context . getTransform ( ) ;
152+ const rowTop = ( row : number ) =>
153+ Math . round ( ( originY + row * metrics . height ) * transform . d ) / transform . d ;
154+ const rowWidth = context . canvas . width / transform . a ;
148155 const rowsToDraw = forceFull
149156 ? Array . from ( { length : snapshot . rows } , ( _ , index ) => index )
150157 : [ ...snapshot . dirtyRows ] ;
@@ -172,10 +179,11 @@ export function renderGhosttySnapshot(options: {
172179 for ( const rowIndex of rowsToDraw ) {
173180 const row = snapshot . rowData [ rowIndex ] ;
174181 if ( ! row ) continue ;
175- const top = originY + rowIndex * metrics . height ;
182+ const top = rowTop ( rowIndex ) ;
183+ const height = rowTop ( rowIndex + 1 ) - top ;
176184
177185 context . fillStyle = cssColor ( snapshot . background ) ;
178- context . fillRect ( padding , top , snapshot . cols * metrics . width , metrics . height ) ;
186+ context . fillRect ( 0 , top , rowWidth , height ) ;
179187
180188 let backgroundStart = 0 ;
181189 while ( backgroundStart < row . cells . length ) {
@@ -198,11 +206,11 @@ export function renderGhosttySnapshot(options: {
198206 const width = ( backgroundEnd - backgroundStart ) * metrics . width ;
199207 if ( ! ghosttyColorsEqual ( first . background , snapshot . background ) ) {
200208 context . fillStyle = cssColor ( first . background ) ;
201- context . fillRect ( left , top , width , metrics . height ) ;
209+ context . fillRect ( left , top , width , height ) ;
202210 }
203211 if ( first . selected ) {
204212 context . fillStyle = selectionBackground ;
205- context . fillRect ( left , top , width , metrics . height ) ;
213+ context . fillRect ( left , top , width , height ) ;
206214 }
207215 }
208216 backgroundStart = backgroundEnd ;
@@ -224,7 +232,8 @@ export function renderGhosttySnapshot(options: {
224232 first . text ,
225233 padding + runStart * metrics . width ,
226234 top ,
227- metrics ,
235+ metrics . width ,
236+ height ,
228237 ) ;
229238 }
230239 runStart += 1 ;
@@ -242,7 +251,7 @@ export function renderGhosttySnapshot(options: {
242251 padding + runStart * metrics . width ,
243252 top ,
244253 ( runEnd - runStart ) * metrics . width ,
245- metrics . height ,
254+ height ,
246255 ) ;
247256 context . clip ( ) ;
248257 context . font = fontForCell ( first , fontSize , fontFamily ) ;
@@ -283,25 +292,26 @@ export function renderGhosttySnapshot(options: {
283292
284293 if ( cursorOn && snapshot . cursorVisible && snapshot . cursorX >= 0 && snapshot . cursorY >= 0 ) {
285294 const left = padding + snapshot . cursorX * metrics . width ;
286- const top = originY + snapshot . cursorY * metrics . height ;
295+ const top = rowTop ( snapshot . cursorY ) ;
296+ const height = rowTop ( snapshot . cursorY + 1 ) - top ;
287297 context . fillStyle = cssColor ( snapshot . cursor ) ;
288298 if ( ! focused ) {
289299 context . strokeStyle = cssColor ( snapshot . cursor ) ;
290- context . strokeRect ( left + 0.5 , top + 0.5 , metrics . width - 1 , metrics . height - 1 ) ;
300+ context . strokeRect ( left + 0.5 , top + 0.5 , metrics . width - 1 , height - 1 ) ;
291301 } else if ( snapshot . cursorStyle === 0 ) {
292- context . fillRect ( left , top , 2 , metrics . height ) ;
302+ context . fillRect ( left , top , 2 , height ) ;
293303 } else if ( snapshot . cursorStyle === 2 ) {
294- context . fillRect ( left , top + metrics . height - 2 , metrics . width , 2 ) ;
304+ context . fillRect ( left , top + height - 2 , metrics . width , 2 ) ;
295305 } else if ( snapshot . cursorStyle === 3 ) {
296306 context . strokeStyle = cssColor ( snapshot . cursor ) ;
297- context . strokeRect ( left + 0.5 , top + 0.5 , metrics . width - 1 , metrics . height - 1 ) ;
307+ context . strokeRect ( left + 0.5 , top + 0.5 , metrics . width - 1 , height - 1 ) ;
298308 } else {
299- context . fillRect ( left , top , metrics . width , metrics . height ) ;
309+ context . fillRect ( left , top , metrics . width , height ) ;
300310 const cell = snapshot . rowData [ snapshot . cursorY ] ?. cells [ snapshot . cursorX ] ;
301311 if ( cell ?. text ) {
302312 context . fillStyle = cssColor ( snapshot . background ) ;
303313 if ( isSolidPowerlineSeparator ( cell . text ) ) {
304- fillSolidPowerlineSeparator ( context , cell . text , left , top , metrics ) ;
314+ fillSolidPowerlineSeparator ( context , cell . text , left , top , metrics . width , height ) ;
305315 } else {
306316 context . font = fontForCell ( cell , fontSize , fontFamily ) ;
307317 context . fillText ( cell . text , left , top + metrics . baseline , metrics . width ) ;
0 commit comments