From 8b5df691eca2354c696dc85deeba4eee327fe871 Mon Sep 17 00:00:00 2001 From: MarcoJayUsai Date: Fri, 22 Nov 2024 15:14:57 +0100 Subject: [PATCH] fix(selected unit coords): failsafe in case of absence of the navigator element --- frontend/website/src/panels/mouseinfopanel.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/frontend/website/src/panels/mouseinfopanel.ts b/frontend/website/src/panels/mouseinfopanel.ts index c36ac803..dc71a5a0 100644 --- a/frontend/website/src/panels/mouseinfopanel.ts +++ b/frontend/website/src/panels/mouseinfopanel.ts @@ -116,6 +116,8 @@ export class MouseInfoPanel extends Panel { #listenForCopyableElements() { const copyableElements = document.getElementsByClassName('copyable'); + // TODO: copy all the coordinates and elevation instead of copying only lat, lng or elevation. + for (const element of copyableElements) { element.addEventListener('contextmenu', (ev) => { if (!ev.target) return; @@ -134,12 +136,14 @@ export class MouseInfoPanel extends Panel { if (!text) return; + if(!navigator || !navigator.clipboard) return; + navigator.clipboard.writeText(text) .then(() => { - //console.log('Testo copiato negli appunti!'); + // Text copied to clipboard. TODO: add a toast or alert for this event. }) .catch(err => { - console.error('Errore nel copiare:', err); + console.error('An error occurred while copying text to clipboard: ', err); }); }); }