diff --git a/nw/gui/custom.py b/nw/gui/custom.py index 03fc6318..2955c447 100644 --- a/nw/gui/custom.py +++ b/nw/gui/custom.py @@ -326,7 +326,7 @@ class QSwitch(QAbstractButton): """ super().mouseReleaseEvent(event) if event.button() == Qt.LeftButton: - doAnim = QPropertyAnimation(self, b'offset', self) + doAnim = QPropertyAnimation(self, b"offset", self) doAnim.setDuration(120) doAnim.setStartValue(self.offset) if self.isChecked(): diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index a7779845..34ae52f2 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -38,7 +38,7 @@ from time import time from PyQt5.QtCore import ( Qt, QSize, QTimer, pyqtSlot, pyqtSignal, QRegExp, QRegularExpression, - QPointF, QObject, QRunnable + QPointF, QObject, QRunnable, QPropertyAnimation ) from PyQt5.QtGui import ( QTextCursor, QTextOption, QKeySequence, QFont, QColor, QPalette, @@ -774,11 +774,22 @@ class GuiDocEditor(QTextEdit): if self.mainConf.scollWithCursor: kMod = keyEvent.modifiers() if kMod == Qt.NoModifier or kMod == Qt.ShiftModifier: + hWid = self.viewport().height() cPos = self.cursorRect().center().y() - mPos = self.mainConf.scollToPoint * self.viewport().height() + mPos = self.mainConf.scollToPoint * hWid vBar = self.verticalScrollBar() - vBar.setValue(vBar.value() + cPos - round(mPos * 0.01)) - self.ensureCursorVisible() + + # Compute the needed scroll and duration + pOld = vBar.value() + pNew = pOld + cPos - round(mPos*0.01) + aDur = 150 + round(abs(pNew - pOld)/hWid*500) + + if pNew >= 0: + doAnim = QPropertyAnimation(vBar, b"value", self) + doAnim.setDuration(aDur) + doAnim.setStartValue(pOld) + doAnim.setEndValue(pNew) + doAnim.start() return