Skip to content

Commit

Permalink
Prevent users from accidentally throwing away edits, by making the Es…
Browse files Browse the repository at this point in the history
…cape key also finish, not cancel
  • Loading branch information
dabreegster committed Dec 5, 2024
1 parent bc9be84 commit 870ef0e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
22 changes: 15 additions & 7 deletions src/lib/draw/area/AreaControls.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,24 @@
let tag = (e.target as HTMLElement).tagName;
let formFocused = tag == "INPUT" || tag == "TEXTAREA";
if (e.key === "Enter" && !formFocused) {
if (e.key == "Enter" && !formFocused) {
e.stopPropagation();
if ($waypoints.length >= 3) {
finish();
} else {
window.alert(
"You can't save this area unless it has at least three points. Press 'Cancel' to discard these changes.",
);
}
} else if (e.key === "Escape") {
} else if (e.key == "Escape") {
e.stopPropagation();
cancel();
if ($waypoints.length >= 3) {
finish();
} else {
window.alert(
"You can't save this area unless it has at least three points. Press 'Cancel' to discard these changes.",
);
}
} else if (e.key == "s" && !formFocused) {
toggleSnap();
} else if (e.key == "z" && e.ctrlKey) {
Expand Down Expand Up @@ -315,11 +325,9 @@
</li>
<li>
<b>Enter</b>
to finish
</li>
<li>
or
<b>Escape</b>
to cancel
to finish
</li>
</ul>
</HelpButton>
Expand Down
10 changes: 8 additions & 2 deletions src/lib/draw/point/PointControls.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@
}
function keyDown(e: KeyboardEvent) {
if (e.key === "Escape") {
if (e.key == "Escape") {
e.stopPropagation();
cancel();
if ($pointPosition) {
finish();
} else {
window.alert(
"You can't save this point until you place it on the map. Press 'Cancel' to discard these changes.",
);
}
}
}
</script>
Expand Down
22 changes: 15 additions & 7 deletions src/lib/draw/route/RouteControls.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,24 @@
let tag = (e.target as HTMLElement).tagName;
let formFocused = tag == "INPUT" || tag == "TEXTAREA";
if (e.key === "Enter" && !formFocused) {
if (e.key == "Enter" && !formFocused) {
e.stopPropagation();
if ($waypoints.length >= 2) {
finish();
} else {
window.alert(
"You can't save this route unless it has at least two points. Press 'Cancel' to discard these changes.",
);
}
} else if (e.key === "Escape") {
} else if (e.key == "Escape") {
e.stopPropagation();
cancel();
if ($waypoints.length >= 2) {
finish();
} else {
window.alert(
"You can't save this route unless it has at least two points. Press 'Cancel' to discard these changes.",
);
}
} else if (e.key == "s" && !formFocused) {
toggleSnap();
} else if (e.key == "1" && !formFocused) {
Expand Down Expand Up @@ -347,11 +357,9 @@
</li>
<li>
<b>Enter</b>
to finish
</li>
<li>
or
<b>Escape</b>
to cancel
to finish
</li>
</ul>
</HelpButton>
Expand Down

0 comments on commit 870ef0e

Please sign in to comment.