Skip to content

Commit

Permalink
Minor tweaks to copy coordinates functionality (#867)
Browse files Browse the repository at this point in the history
  • Loading branch information
DTTerastar authored Nov 18, 2024
1 parent f7f9217 commit e6560f9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/ui/src/lib/MapCoordinates.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@
if ((event.ctrlKey || event.metaKey) && event.key === 'c') {
event.preventDefault();
hasFocus = true;
const coords = ` - [${cursorX.toFixed(2)},${cursorY.toFixed(2)}]`;
const roundedX = Math.round(cursorX * 10) / 10;
const roundedY = Math.round(cursorY * 10) / 10;
const coords = ` - [${roundedX},${roundedY}]`;
copiedCoords = [...copiedCoords, coords];
navigator.clipboard
.writeText(copiedCoords.join('\n'))
.then(() => {
toastStore.trigger({
message: `Copied ${copiedCoords.length} coordinate${copiedCoords.length > 1 ? 's' : ''} to clipboard!`,
background: 'variant-filled-success'
background: 'variant-filled-success',
timeout: 1000
});
})
.catch((error) => {
Expand All @@ -67,7 +70,8 @@
copiedCoords = [];
toastStore.trigger({
message: 'Coordinate collection reset',
background: 'variant-filled-primary'
background: 'variant-filled-primary',
timeout: 1000
});
}
}
Expand All @@ -78,6 +82,6 @@
<g transform="translate({$width - 120}, {$height - 40})">
<rect width="110" height="30" rx="4" fill="#2563eb" class="shadow-lg" />
<text x="55" y="19" text-anchor="middle" fill="white" font-size="12">
X: {cursorX.toFixed(2)}, Y: {cursorY.toFixed(2)}
X: {Math.round(cursorX * 10) / 10}, Y: {Math.round(cursorY * 10) / 10}
</text>
</g>

0 comments on commit e6560f9

Please sign in to comment.