From d090f3e6513fe519041d3fb29567786d0320b864 Mon Sep 17 00:00:00 2001 From: Frans de Jonge Date: Sat, 23 Feb 2019 21:34:03 +0100 Subject: [PATCH] [fix, UX] GestureDetector: fix multiswipe length detection (#4649) Reported by @poire-z, cf. https://github.com/koreader/koreader/pull/4640#issuecomment-466544922 Apparently it's natural for me to make the second swipe slightly longer than the first, so I never noticed a logic issue. I did notice that it seemed slightly harder to make 4-swipe multiswipes than I expected it to be, but those are not necessarily easy gestures to make. The problem was that I needed to prevent obviously silly gestures like west west west east. In ignoring such duplication, what I accidentally did was to ignore any further movement west after the first multiswipe direction was detected, meaning that the following swipe east could still end up as a relatively western movement overall. By simply updating the current multiswipe slot in case of the same direction, both problems are prevented. We'll never get the same direction twice, and X moves over to where it's supposed to be on the left. --- frontend/device/gesturedetector.lua | 31 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/frontend/device/gesturedetector.lua b/frontend/device/gesturedetector.lua index d8b23a685..73ae15de1 100644 --- a/frontend/device/gesturedetector.lua +++ b/frontend/device/gesturedetector.lua @@ -517,24 +517,23 @@ function GestureDetector:handlePan(tev) ["slot"] = slot, }, } - pan_direction = self:getPath(slot, false, fake_first_tev) end - if msd_cnt == 0 - or pan_direction ~= msd_direction_prev - then - local msd_direction, msd_distance = self:getPath(slot, true, fake_first_tev) - - if msd_distance > self.MULTISWIPE_THRESHOLD - and (msd_cnt == 0 - or not pan_direction:match(msd_direction_prev)) - then - if msd_direction ~= msd_direction_prev then - self.multiswipe_directions[msd_cnt+1] = { - [1] = msd_direction, - [2] = pan_ev, - } - end + -- the first time fake_first_tev is nil, so self.first_tevs is automatically used instead + local msd_direction, msd_distance = self:getPath(slot, true, fake_first_tev) + + if msd_distance > self.MULTISWIPE_THRESHOLD then + if msd_direction ~= msd_direction_prev then + self.multiswipe_directions[msd_cnt+1] = { + [1] = msd_direction, + [2] = pan_ev, + } + -- update ongoing swipe direction to the new maximum + else + self.multiswipe_directions[msd_cnt] = { + [1] = msd_direction, + [2] = pan_ev, + } end end