From 68f876ec6bdbe551cd0509a8623adee05d8c0176 Mon Sep 17 00:00:00 2001 From: HikeMap User Date: Sat, 10 Jan 2026 20:49:47 -0600 Subject: [PATCH] Fix GPS test mode toggle and WASD button state issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Restart GPS tracking when disabling test mode - Add resetWasdState() to clean up movement interval on mode toggle - Add lostpointercapture handler for when buttons are hidden mid-press - Add pointerleave handler for edge cases - Reset WASD state when enabling or disabling test mode 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- index.html | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index ea90997..da7461b 100644 --- a/index.html +++ b/index.html @@ -6710,7 +6710,8 @@ gpsBackupInterval = null; } - // Show WASD controls + // Reset WASD state and show controls + resetWasdState(); const wasdControls = document.getElementById('wasdControls'); if (wasdControls) wasdControls.classList.remove('hidden'); @@ -6722,7 +6723,16 @@ // Hide WASD controls when disabling test mode const wasdControls = document.getElementById('wasdControls'); if (wasdControls) wasdControls.classList.add('hidden'); - updateStatus('GPS Test Mode disabled', 'info'); + + // Clean up any active WASD movement state + resetWasdState(); + + // Restart GPS tracking since user wants to use real GPS + if (gpsWatchId === null) { + toggleGPS(); + } + + updateStatus('GPS Test Mode disabled - starting GPS', 'info'); } } @@ -6924,6 +6934,23 @@ } }); + // Handle lost pointer capture (e.g., when element is hidden) + btn.addEventListener('lostpointercapture', (e) => { + if (isPressed) { + isPressed = false; + stopMove(); + } + }); + + // Handle pointer leaving button area + btn.addEventListener('pointerleave', (e) => { + // Only stop if we have capture (otherwise normal hover exit) + if (isPressed && !btn.hasPointerCapture(e.pointerId)) { + isPressed = false; + stopMove(); + } + }); + // Prevent context menu on long press btn.addEventListener('contextmenu', (e) => { e.preventDefault(); @@ -6931,6 +6958,15 @@ }); } + // Function to reset WASD state (call when showing/hiding controls) + function resetWasdState() { + if (wasdMoveInterval) { + clearInterval(wasdMoveInterval); + wasdMoveInterval = null; + } + wasdCurrentDir = null; + } + // Initialize WASD controls after DOM is ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initWasdControls);