Skip to content

Commit 3c9f460

Browse files
committed
closing maximized diff view using ESC
1 parent ea948d2 commit 3c9f460

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/Frontend/src/components/messages2/DiffViewer.vue

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { ref, computed, watch } from "vue";
2+
import { ref, computed, watch, onMounted, onBeforeUnmount } from "vue";
33
import * as diff from "diff";
44
55
// Types needed for the diff viewer
@@ -269,6 +269,13 @@ const toggleMaximizeModal = () => {
269269
showMaximizeModal.value = !showMaximizeModal.value;
270270
};
271271
272+
// Handle ESC key to close modal
273+
const handleKeyDown = (event: KeyboardEvent) => {
274+
if (event.key === "Escape" && showMaximizeModal.value) {
275+
showMaximizeModal.value = false;
276+
}
277+
};
278+
272279
// Handle mouse enter/leave for showing maximize button
273280
const onDiffMouseEnter = () => {
274281
if (props.showMaximizeIcon) {
@@ -279,6 +286,19 @@ const onDiffMouseEnter = () => {
279286
const onDiffMouseLeave = () => {
280287
showMaximizeButton.value = false;
281288
};
289+
290+
// Ensure modal resizes with window and setup keyboard events
291+
onMounted(() => {
292+
if (props.showMaximizeIcon) {
293+
// Add keyboard event listener for ESC key
294+
window.addEventListener("keydown", handleKeyDown);
295+
}
296+
});
297+
298+
// Clean up event listeners when component is destroyed
299+
onBeforeUnmount(() => {
300+
window.removeEventListener("keydown", handleKeyDown);
301+
});
282302
</script>
283303

284304
<template>

0 commit comments

Comments
 (0)