From 71a533ec343be01082a1ea582eb69cc5014fb71a Mon Sep 17 00:00:00 2001 From: Gregor Lohaus Date: Sun, 31 May 2026 18:05:57 +0200 Subject: [PATCH] clear context new fix --- .../jprototerm/GhosttyTerminalRenderer.java | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/gregor/jprototerm/GhosttyTerminalRenderer.java b/src/main/java/com/gregor/jprototerm/GhosttyTerminalRenderer.java index 471d302..63ed40a 100644 --- a/src/main/java/com/gregor/jprototerm/GhosttyTerminalRenderer.java +++ b/src/main/java/com/gregor/jprototerm/GhosttyTerminalRenderer.java @@ -101,11 +101,7 @@ final class GhosttyTerminalRenderer extends TerminalRenderer { if (dirty == DIRTY_FULL) { software.paintFullOrShifted(gc, target.snapshotFull(), px, py, width, height, active); } else if (dirty == DIRTY_PARTIAL) { - if (snapshot != null && snapshot.renderRows().size() == snapshot.rows()) { - software.paintFullOrShifted(gc, snapshot, px, py, width, height, active); - } else { - software.paintDirty(gc, snapshot, px, py, width, height, active); - } + software.paintDirty(gc, target, snapshot, px, py, width, height, active); } // dirty == FALSE: nothing visible changed. } @@ -735,14 +731,14 @@ final class GhosttyTerminalRenderer extends TerminalRenderer { present(gc, px, py); } - private void paintDirty(GraphicsContext gc, RenderStateSnapshot snapshot, + private void paintDirty(GraphicsContext gc, RenderTarget target, RenderStateSnapshot snapshot, double px, double py, double paneWidth, double paneHeight, boolean active) { ensure(paneWidth, paneHeight); if (snapshot == null) { return; } if (rowHashes.length != snapshot.rows()) { - paintFull(gc, snapshot, px, py, paneWidth, paneHeight, active); + paintFull(gc, target.snapshotFull(), px, py, paneWidth, paneHeight, active); return; } @@ -751,6 +747,7 @@ final class GhosttyTerminalRenderer extends TerminalRenderer { int newCursorRow = cursor.viewportRow(); boolean cursorChanged = !cursor.equals(lastCursor); boolean[] repainted = new boolean[snapshot.rows()]; + boolean needsCursorDraw = cursorChanged; for (RenderRow row : snapshot.renderRows()) { if (!row.dirty()) { @@ -759,28 +756,46 @@ final class GhosttyTerminalRenderer extends TerminalRenderer { paintRow(row); rowHashes[row.row()] = rowHash(row); repainted[row.row()] = true; + if (row.row() == newCursorRow) { + needsCursorDraw = true; + } } if (cursorChanged) { - repaintCursorRow(snapshot, oldCursorRow, repainted); + if (!repaintCursorRow(snapshot, oldCursorRow, repainted)) { + paintFullOrShifted(gc, target.snapshotFull(), px, py, paneWidth, paneHeight, active); + return; + } + } + if (repaintedRowHasCursor(newCursorRow, repainted) + && !repaintCursorRow(snapshot, newCursorRow, repainted)) { + paintFullOrShifted(gc, target.snapshotFull(), px, py, paneWidth, paneHeight, active); + return; } - repaintCursorRow(snapshot, newCursorRow, repainted); lastCursor = cursor; - drawCursor(snapshot); + if (needsCursorDraw) { + drawCursor(snapshot); + } drawBorder(active); present(gc, px, py); } - private void repaintCursorRow(RenderStateSnapshot snapshot, int rowIndex, boolean[] repainted) { + private boolean repaintCursorRow(RenderStateSnapshot snapshot, int rowIndex, boolean[] repainted) { if (rowIndex < 0 || rowIndex >= repainted.length || repainted[rowIndex]) { - return; + return true; } RenderRow row = rowByIndex(snapshot, rowIndex); - if (row != null) { - paintRow(row); - rowHashes[rowIndex] = rowHash(row); - repainted[rowIndex] = true; + if (row == null || !row.dirty()) { + return false; } + paintRow(row); + rowHashes[rowIndex] = rowHash(row); + repainted[rowIndex] = true; + return true; + } + + private boolean repaintedRowHasCursor(int rowIndex, boolean[] repainted) { + return rowIndex >= 0 && rowIndex < repainted.length && repainted[rowIndex]; } private RenderRow rowByIndex(RenderStateSnapshot snapshot, int rowIndex) {