From d4d18a01ced1a18adf567eb51ca0c294bae3e0eb Mon Sep 17 00:00:00 2001
From: Cameron Cawley <ccawley2011@gmail.com>
Date: Wed, 16 Feb 2022 19:36:55 +0000
Subject: [PATCH] gtk: Fix the caret position when scrolling with GTK3

---
 frontends/gtk/window.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/frontends/gtk/window.c b/frontends/gtk/window.c
index f5c87ef87..4a08510d0 100644
--- a/frontends/gtk/window.c
+++ b/frontends/gtk/window.c
@@ -172,6 +172,8 @@ nsgtk_window_draw_event(GtkWidget *widget, cairo_t *cr, gpointer data)
 	double y1;
 	double x2;
 	double y2;
+	double sx;
+	double sy;
 
 	assert(gw);
 	assert(gw->bw);
@@ -193,14 +195,17 @@ nsgtk_window_draw_event(GtkWidget *widget, cairo_t *cr, gpointer data)
 	clip.x1 = x2;
 	clip.y1 = y2;
 
+	sx = gtk_adjustment_get_value(hscroll);
+	sy = gtk_adjustment_get_value(vscroll);
+
 	browser_window_redraw(gw->bw,
-			      -gtk_adjustment_get_value(hscroll),
-			      -gtk_adjustment_get_value(vscroll),
+			      -sx,
+			      -sy,
 			      &clip,
 			      &ctx);
 
 	if (gw->careth != 0) {
-		nsgtk_plot_caret(gw->caretx, gw->carety, gw->careth);
+		nsgtk_plot_caret(gw->caretx - sx, gw->carety -sy, gw->careth);
 	}
 
 	return FALSE;
-- 
2.30.2

