simjanos-dev / LinguaCafe

LinguaCafe is a self-hosted software that helps language learners read foreign languages.
https://simjanos-dev.github.io/LinguaCafeHome/
GNU General Public License v3.0
888 stars 32 forks source link

fix: only clear timeout if the ongoingSelection is not empty #274

Closed mateuszmrw closed 6 months ago

mateuszmrw commented 6 months ago

Closes: #262

Sorry for another one line PR.

It seems that for Apple Pencil touch events the updateSelectionTouchEvent function is called right away after the startSelectionTouchEvent, meaning that the function inside the touchTimer setTimeout never executes due to clearTimeout. This leaves the ongoingSelection array empty meaning that the updateSelection is never called due to this if:

   if (wordIndex !== null && this.ongoingSelection.length) {
      this.updateSelection(wordIndex);
   }

This PR fixes it by only calling the clearTimeout if the this.touchTimer exists and the ongoingSelection is not empty

simjanos-dev commented 6 months ago

Sorry for another one line PR.

I always appreciate PR-s and bug reports to improve linguacafe.

The changes in the PR remove intended functionality: there should be half a second wait time after touching before the user can select multiple words.

I did this because on multiple phones there is a vibration when you keep touching something and don't move your finger. And recently, I thought about adding a hover vocabulary box functionality for tapping a word quickly on touch devices.

Based on your description, does this commit fix the problem for you with apple pencils? Now if the updateSelectionTouchEvent gets called during the 0.5s wait on the same word as the one you started the selection with, nothing will happen. It will only get canceled if you move the pencil enough start scrolling, or you move the pencil outside of the word.

(This is part 2 of a previous commit.)

simjanos-dev commented 6 months ago

It was confirmed on discord that it is working.