[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [ktexteditor] src/view: Fix: Scroll view lines instead of real lines for wheel and touchpad scrollin
From:       Sven Brauch <null () kde ! org>
Date:       2018-08-13 8:47:08
Message-ID: E1fp8VI-0000jU-HK () code ! kde ! org
[Download RAW message or body]

Git commit 2815fea7854fae5ef45d8bb6d4ec61960576e5df by Sven Brauch.
Committed on 13/08/2018 at 08:44.
Pushed by brauch into branch 'master'.

Fix: Scroll view lines instead of real lines for wheel and touchpad scrolling

In documents with very long lines (think LaTeX files in case people don't
put linebreaks except for paragraphs) with dynwrap on, scrolling used
to be very difficult, since using the mouse wheel would always scroll one
real line at a time, which could be something like 10 view lines.

This patch instead scrolls by view lines if the mouse wheel is used.

Differential Revision: https://phabricator.kde.org/D14758
BUG: 256561

M  +17   -4    src/view/kateviewinternal.cpp
M  +1    -0    src/view/kateviewinternal.h

https://commits.kde.org/ktexteditor/2815fea7854fae5ef45d8bb6d4ec61960576e5df

diff --git a/src/view/kateviewinternal.cpp b/src/view/kateviewinternal.cpp
index 9ecd34f9..49513c9a 100644
--- a/src/view/kateviewinternal.cpp
+++ b/src/view/kateviewinternal.cpp
@@ -3377,11 +3377,24 @@ void KateViewInternal::wheelEvent(QWheelEvent *e)
 
     // handle vertical scrolling via the scrollbar
     if (e->orientation() == Qt::Vertical) {
-        QWheelEvent copy = *e;
-        QApplication::sendEvent(m_lineScroll, &copy);
-        if (copy.isAccepted()) {
-            e->accept();
+        // compute distance
+        auto sign = m_lineScroll->invertedControls() ? -1 : 1;
+        auto offset = sign * qreal(e->angleDelta().y()) / 120.0;
+        if ( e->modifiers() & Qt::ShiftModifier ) {
+            const auto pageStep = m_lineScroll->pageStep();
+            offset = qBound(-pageStep, int(offset * pageStep), pageStep);
+        } else {
+            offset *= QApplication::wheelScrollLines();
         }
+
+        // handle accumulation
+        m_accumulatedScroll += offset - int(offset);
+        const auto extraAccumulated = int(m_accumulatedScroll);
+        m_accumulatedScroll -= extraAccumulated;
+
+        // do scroll
+        scrollViewLines(int(offset) + extraAccumulated);
+        e->accept();
     }
 
     // handle horizontal scrolling via the scrollbar
diff --git a/src/view/kateviewinternal.h b/src/view/kateviewinternal.h
index 642cac47..4d26dbc9 100644
--- a/src/view/kateviewinternal.h
+++ b/src/view/kateviewinternal.h
@@ -319,6 +319,7 @@ private:
     // line scrollbar + first visible (virtual) line in the current view
     //
     KateScrollBar *m_lineScroll;
+    qreal m_accumulatedScroll = 0.0;
     QWidget *m_dummy;
 
     // These are now cursors to account for word-wrap.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic