lichess-org / chessground

Mobile/Web chess UI for lichess.org
https://lichess.org
GNU General Public License v3.0
1.01k stars 260 forks source link

Arrow doesn't snap to valid move after mouse re-enters DOM #280

Closed ch-iv closed 11 months ago

ch-iv commented 11 months ago

When an arrow is drawn, by default it should snap to a valid move. However after the mouse leaves the board DOM and then re-enters, the arrow stops snapping to a valid move. This is caused by the following code in the processDraw function of draw.ts.

if (!keyAtDomPos) {
  cur.snapToValidMove = false;
}

I think originally this was meant to completely prevent the arrow from being drawn when mouse leaves the DOM, but the state of cur.snapToValidMove does not get set to the original value after the mouse re-enters the DOM. If this behavior is not intentional, I suggest the following fix:

cur.snapToValidMove = keyAtDomPos ? false : state.drawable.defaultSnapToValidMove;

If this is confirmed to be a bug, I'll be happy to create a pull request.

niklasf commented 11 months ago

Hi. This is actually a weird but useful feature (#147).