retejs / rete

JavaScript framework for visual programming
https://retejs.org
MIT License
10.17k stars 653 forks source link

Translating locked when release click out of editor div #354

Closed jprustv closed 5 years ago

jprustv commented 5 years ago

Hello,

I was facing an issue where when I was trying to translate the editor area, if I happened to release the mouse's left button outside of the editor content div, the editor.view.area.transform was getting odd values. K was being set to 1, X and Y were being set to NaN.

chatbotBugRete

After some debugging I found out that at this line of zoom.ts , on move() function: let delta = distance / this.previous.distance - 1; the this.previous.distance had 0 (zero) as value, which was causing delta to become NaN and consequently, that bug.

The solution I found was to add another condition before that line to check if the value was 0, so: if (this.previous !== null) { became if (this.previous !== null && this.previous.distance != 0) {

This almost fixed the bug, except that at down() function, the translating was getting locked for my next click as I noticed that at my next click the this.pointers array had two pointers. To fix that I changed this: this.onlock(true); to this.onlock(false);

This apparently fixed everything for me, but since I'm not sure what was the original intention of having that onlock(true) there (maybe for mobile devices?), I suggest that you investigate this further and maybe find a more clean solution.

Ni55aN commented 5 years ago

this.onlock is intended to prevent translation when zooming on the touch screen

Ni55aN commented 5 years ago

there is problem with a missed pointerup event: end() will not be triggered and translation will be locked

Ni55aN commented 5 years ago

Fixed in v1.4.1-rc.2. Please test it

jprustv commented 5 years ago

Tested. Working like a charm ! Thank you!