Skip to content

Commit

Permalink
Merge pull request #12 from bdon/secret-shortcut
Browse files Browse the repository at this point in the history
add secret geojson paste shortcut
  • Loading branch information
bdon authored Aug 29, 2024
2 parents e6506fd + b80cb03 commit 12bb6ba
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,37 @@ function App() {
);
}
});

// secret paste polygon from clipboard command
var keyMap: { [name: string]: boolean } = {};
window.onkeydown = window.onkeyup = async (e) => {
keyMap[e.code] = e.type == "keydown";
if (e.type != "keydown") return;

// cntrl + shift + v
if (Object.keys(keyMap).length !== 3) return;
if (!keyMap["ControlLeft"] || !keyMap["ShiftLeft"] || !keyMap["KeyV"]) {
return;
}

try {
console.error("secret keyboard shortcut activated!!");
if (!navigator?.clipboard) throw new Error("clipboard API unavailable");
const clip = await navigator.clipboard.readText();
const polygon = JSON.parse(clip);
if (polygon?.type !== "Feature") {
throw new Error("invalid feature");
}
if (polygon?.geometry?.type !== "Polygon") {
throw new Error("invalid polygon");
}
const covering = getCovering(regionCoverer, [polygon]);
displayCovering(covering);
} catch (e) {
console.error("clipboard paste failed");
console.error(e);
}
};
});

return (
Expand Down

0 comments on commit 12bb6ba

Please sign in to comment.