feat: ESC zamyka wszystkie modale (Custom Game, Simulation, Win)

This commit is contained in:
2026-02-12 13:51:10 +01:00
parent 82a3717689
commit 57ae54d716
2 changed files with 27 additions and 1 deletions

View File

@@ -156,6 +156,7 @@ const stopDrag = () => {
onUnmounted(() => {
window.removeEventListener('mousemove', onDrag);
window.removeEventListener('mouseup', stopDrag);
window.removeEventListener('keydown', onKeyDown);
});
const showAdvanced = ref(false);
@@ -169,6 +170,16 @@ const toggleAdvanced = () => {
}
};
const handleClose = () => {
emit('close');
};
const onKeyDown = (e) => {
if (e.key === 'Escape') {
handleClose();
}
};
onMounted(() => {
const savedSize = localStorage.getItem('nonograms_custom_size');
if (savedSize && !isNaN(savedSize)) {
@@ -181,6 +192,7 @@ onMounted(() => {
}
// Don't draw map initially if hidden
window.addEventListener('keydown', onKeyDown);
});
watch([customSize, fillRate], () => {

View File

@@ -1,6 +1,6 @@
<script setup>
import { ref, computed } from 'vue';
import { ref, computed, onMounted, onUnmounted } from 'vue';
import { generateRandomGrid, calculateHints } from '@/utils/puzzleUtils';
import { solvePuzzle } from '@/utils/solver';
import { useI18n } from '@/composables/useI18n';
@@ -21,6 +21,20 @@ const simulationSpeed = ref(1); // 1 = Normal, 2 = Fast (less render updates)
let stopRequested = false;
const onKeyDown = (e) => {
if (e.key === 'Escape') {
emit('close');
}
};
onMounted(() => {
window.addEventListener('keydown', onKeyDown);
});
onUnmounted(() => {
window.removeEventListener('keydown', onKeyDown);
});
const displayStatus = computed(() => {
if (!currentStatus.value) return t('simulation.status.ready');
return currentStatus.value;