Skip to content

Commit

Permalink
Save current image from the gallery view by pressing Ctrl-S
Browse files Browse the repository at this point in the history
  • Loading branch information
pelya committed Dec 19, 2023
1 parent c6c0723 commit ef67a98
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ts/components/Lightbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export function Lightbox({
}, [setVideoTime, videoElement]);

const handleSave = (
event: React.MouseEvent<HTMLButtonElement, MouseEvent>
event: KeyboardEvent | React.MouseEvent<HTMLButtonElement, MouseEvent>
) => {
if (isViewOnce) {
return;
Expand Down Expand Up @@ -193,6 +193,8 @@ export function Lightbox({

const onKeyDown = useCallback(
(event: KeyboardEvent) => {
const isMacOS = (window.platform === 'darwin');

switch (event.key) {
case 'Escape': {
closeLightbox();
Expand All @@ -211,10 +213,16 @@ export function Lightbox({
onNext(event);
break;

case 's':
if (isMacOS ? event.metaKey : event.ctrlKey) {
handleSave(event);
}
break;

default:
}
},
[closeLightbox, onNext, onPrevious]
[closeLightbox, onNext, onPrevious, handleSave]
);

const onClose = (event: React.MouseEvent<HTMLElement>) => {
Expand Down

0 comments on commit ef67a98

Please sign in to comment.