diff --git a/src/components/coordkeeper.jsx b/src/components/coordkeeper.jsx index 3c3e4a4..f6f594b 100644 --- a/src/components/coordkeeper.jsx +++ b/src/components/coordkeeper.jsx @@ -44,6 +44,40 @@ export default function Keeper({ tipo }) { } }, [tipo]); + useEffect(() => { + const handlePaste = async (e) => { + const text = await navigator.clipboard.readText(); + const regex = /- (.*), X: (-?\d+)(?:\s*Y:\s*(-?\d+))?\s*Z:\s*(-?\d+)/; + const match = text.match(regex); + + if (match) { + const [_, descripcion, x, y, z] = match; + const newCoord = { + descripcion, + x: parseInt(x), + y: y ? parseInt(y) : null, + z: parseInt(z), + num: coords.length + 1, + }; + + const newCoords = [...coords, newCoord]; + setCoords(newCoords); + localStorage.setItem(tipo, JSON.stringify(newCoords)); + setShowToast(true); + } + }; + + document.addEventListener("keydown", (e) => { + if (e.ctrlKey && e.key === "v") { + handlePaste(e); + } + }); + + /*return () => { + document.removeEventListener("keydown", handlePaste); + };*/ + }, [coords, tipo]); + const Editar = (coord) => { setCoord(coord); setEditar(true);