From af4f7ef3f0d383dcbcc91199846f00f94dfc7e53 Mon Sep 17 00:00:00 2001 From: "Christopher T. Johnson" Date: Wed, 13 Mar 2024 16:47:37 -0400 Subject: [PATCH] Stop endless scrolling When a scroll is unable to complete by moving text up or down, the timer continues to run. Every tick it attempts to scroll the text. This happens if you are on the last paragraph and click scroll. The page scrolls upwards until it can no longer scroll. It locks there. The timer keeps trying to move the text, but that is not visible. When the user goes to the next section, the scroll is still running and will continue the scroll. If the new section is shorter than the previous section, the scroll will never stop. Fixes: #5 --- lib/read.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/read.py b/lib/read.py index 334bbe3..f702851 100644 --- a/lib/read.py +++ b/lib/read.py @@ -206,6 +206,8 @@ class ReadDialog(QDialog, Ui_ReadDialog): if msPerTick < 3: msPerTick = 3 self.target = value + delta + if self.target > self.paraEdit.verticalScrollBar().maximum(): + self.target = self.paraEdit.verticalScrollBar().maximum() - 1 timer = QTimer(self) timer.timeout.connect(self.softTick) timer.start(msPerTick) @@ -214,6 +216,7 @@ class ReadDialog(QDialog, Ui_ReadDialog): @pyqtSlot() def softTick(self) -> None: value = self.paraEdit.verticalScrollBar().value() + maxValue = self.paraEdit.verticalScrollBar().maximum() sender: QTimer = cast(QTimer, self.sender()) if self.pxPerTick < 0: # moving content up if value < self.target: