fix: priorytet ESC i zatrzymanie propagacji w modalach

This commit is contained in:
2026-02-12 13:58:28 +01:00
parent c197445f35
commit d7e104c17a
4 changed files with 22 additions and 13 deletions

View File

@@ -28,6 +28,21 @@ const appVersion = __APP_VERSION__;
let displayModeMedia = null;
let prefersColorSchemeMedia = null;
const onKeyDownGlobal = (e) => {
if (e.key !== 'Escape') return;
if (showSimulation.value) {
showSimulation.value = false;
return;
}
if (showCustomModal.value) {
showCustomModal.value = false;
return;
}
if (store.isGameWon) {
store.closeWinModal();
}
};
const installLabel = computed(() => {
return isCoarsePointer.value ? t('pwa.installMobile') : t('pwa.installDesktop');
});
@@ -114,6 +129,7 @@ onMounted(() => {
} else if (displayModeMedia?.addListener) {
displayModeMedia.addListener(updateStandalone);
}
window.addEventListener('keydown', onKeyDownGlobal);
}
});
@@ -131,6 +147,7 @@ onUnmounted(() => {
} else if (displayModeMedia?.removeListener) {
displayModeMedia.removeListener(updateStandalone);
}
window.removeEventListener('keydown', onKeyDownGlobal);
});
</script>

View File

@@ -156,7 +156,6 @@ const stopDrag = () => {
onUnmounted(() => {
window.removeEventListener('mousemove', onDrag);
window.removeEventListener('mouseup', stopDrag);
window.removeEventListener('keydown', onKeyDown);
});
const showAdvanced = ref(false);
@@ -170,16 +169,6 @@ 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)) {
@@ -192,7 +181,6 @@ onMounted(() => {
}
// Don't draw map initially if hidden
window.addEventListener('keydown', onKeyDown);
});
watch([customSize, fillRate], () => {

View File

@@ -23,6 +23,8 @@ let stopRequested = false;
const onKeyDown = (e) => {
if (e.key === 'Escape') {
e.stopImmediatePropagation?.();
e.preventDefault?.();
emit('close');
}
};

View File

@@ -28,6 +28,8 @@ const handleClose = () => {
const handleKeyDown = (e) => {
if (e.key === 'Escape') {
e.stopImmediatePropagation?.();
e.preventDefault?.();
handleClose();
}
};