diff --git a/src/config.ts b/src/config.ts index 9ca5f9a1..3c290c43 100644 --- a/src/config.ts +++ b/src/config.ts @@ -87,7 +87,7 @@ export interface Config { defaultSnapToValidMove?: boolean; // Clicking an empty square or immovable piece will clear the drawing regardless, but when this property is true, // clicking on a (currently unselected) movable piece will also clear the drawing. - eraseOnMovablePieceClick?: boolean; + eraseOnClick?: boolean; shapes?: DrawShape[]; autoShapes?: DrawShape[]; brushes?: DrawBrushes; diff --git a/src/drag.ts b/src/drag.ts index e0387b99..8f2cb339 100644 --- a/src/drag.ts +++ b/src/drag.ts @@ -29,12 +29,10 @@ export function start(s: State, e: cg.MouchEvent): void { if (!orig) return; const piece = s.pieces.get(orig); const previouslySelected = s.selected; - if ( - !previouslySelected && - s.drawable.enabled && - (s.drawable.eraseOnMovablePieceClick || !piece || piece.color !== s.turnColor) - ) - drawClear(s); + if (!previouslySelected && s.drawable.enabled) { + if (s.drawable.eraseOnClick) drawClear(s); + else if (piece?.color !== s.turnColor) s.pixelCoordsOfMouchDownToMaybeClearShapes = position; + } // Prevent touch scroll and create no corresponding mouse event, if there // is an intent to interact with the board. if ( @@ -159,6 +157,14 @@ export function move(s: State, e: cg.MouchEvent): void { } export function end(s: State, e: cg.MouchEvent): void { + const position = util.eventPosition(e); + if ( + position && + s.pixelCoordsOfMouchDownToMaybeClearShapes && + util.distanceSq(position, s.pixelCoordsOfMouchDownToMaybeClearShapes) < 225 + ) + drawClear(s); + s.pixelCoordsOfMouchDownToMaybeClearShapes = undefined; const cur = s.draggable.current; if (!cur) return; // create no corresponding mouse event diff --git a/src/draw.ts b/src/draw.ts index 5407f98f..2390fde0 100644 --- a/src/draw.ts +++ b/src/draw.ts @@ -44,7 +44,7 @@ export interface Drawable { enabled: boolean; // can draw visible: boolean; // can view defaultSnapToValidMove: boolean; - eraseOnMovablePieceClick: boolean; + eraseOnClick: boolean; onChange?: (shapes: DrawShape[]) => void; shapes: DrawShape[]; // user shapes autoShapes: DrawShape[]; // computer shapes diff --git a/src/state.ts b/src/state.ts index 6f27331a..2e6377c7 100644 --- a/src/state.ts +++ b/src/state.ts @@ -23,6 +23,7 @@ export interface HeadlessState { blockTouchScroll: boolean; // block scrolling via touch dragging on the board touchIgnoreRadius: number; // ignore touches within a radius of an occupied square, in units of its circumradius pieceKey: boolean; // add a data-key attribute to piece elements + pixelCoordsOfMouchDownToMaybeClearShapes?: cg.NumberPair; trustAllEvents?: boolean; // disable checking for human only input (e.isTrusted) highlight: { lastMove: boolean; // add last-move class to squares @@ -176,7 +177,7 @@ export function defaults(): HeadlessState { enabled: true, // can draw visible: true, // can view defaultSnapToValidMove: true, - eraseOnMovablePieceClick: true, + eraseOnClick: true, shapes: [], autoShapes: [], brushes: {