1
1
<script setup lang="ts">
2
- import { ref , computed , watch } from " vue" ;
2
+ import { ref , computed , watch , onMounted , onBeforeUnmount } from " vue" ;
3
3
import * as diff from " diff" ;
4
4
5
5
// Types needed for the diff viewer
@@ -269,6 +269,13 @@ const toggleMaximizeModal = () => {
269
269
showMaximizeModal .value = ! showMaximizeModal .value ;
270
270
};
271
271
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
+
272
279
// Handle mouse enter/leave for showing maximize button
273
280
const onDiffMouseEnter = () => {
274
281
if (props .showMaximizeIcon ) {
@@ -279,6 +286,19 @@ const onDiffMouseEnter = () => {
279
286
const onDiffMouseLeave = () => {
280
287
showMaximizeButton .value = false ;
281
288
};
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
+ });
282
302
</script >
283
303
284
304
<template >
0 commit comments