Add ESC handling

This commit is contained in:
Andrea Fazzi 2023-04-19 12:36:53 +02:00
parent f2bf94371f
commit a4bc66c61d
2 changed files with 19 additions and 5 deletions

View file

@ -13,16 +13,17 @@
padding: 20px; padding: 20px;
color: #fff; color: #fff;
font-family: Arial, sans-serif; font-family: Arial, sans-serif;
width: 300px; /* width: 300px;*/
margin: 10px; margin: 10px;
padding: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
} }
.card:hover { .card:hover {
background-color: #444; background-color: #444;
cursor: pointer; cursor: pointer;
transform: scale(1.05); /* transform: scale(1.05); */
transition: all 0.3s ease; /* transition: all 0.3s ease; */
} }
.question { .question {

View file

@ -1,4 +1,5 @@
<script lang="ts"> <script lang="ts">
import { onMount } from "svelte";
import CodeMirror from "svelte-codemirror-editor"; import CodeMirror from "svelte-codemirror-editor";
import { markdown } from "@codemirror/lang-markdown"; import { markdown } from "@codemirror/lang-markdown";
import QuizCard from "./QuizCard.svelte"; import QuizCard from "./QuizCard.svelte";
@ -10,7 +11,14 @@
let value: string; let value: string;
let editingIndex: number; let editingIndex: number;
function editQuiz(quiz: Quiz, index: number) { onMount(() => {
document.addEventListener("keydown", handleKeydown);
return () => {
document.removeEventListener("keydown", handleKeydown);
};
});
function editQuiz(quiz: main.Quiz, index: number) {
Markdown(quiz).then( Markdown(quiz).then(
(result) => { (result) => {
value = result; value = result;
@ -28,6 +36,11 @@
editingIndex = -1; editingIndex = -1;
} }
function handleKeydown(event: KeyboardEvent) {
if (event.key === "Escape" && editingIndex !== -1) {
editingIndex = -1;
}
}
</script> </script>
<div> <div>