This commit is contained in:
Manav Rathi
2025-03-06 10:53:25 +05:30
parent 63faa29cd4
commit ba95d08cdd
2 changed files with 34 additions and 26 deletions

View File

@@ -642,14 +642,22 @@ const FileViewer: React.FC<FileViewerProps> = ({
openShortcuts, openShortcuts,
]); ]);
const canCopyImage = useCallback(
() =>
activeAnnotatedFile?.annotation.showCopyImage &&
activeAnnotatedFile.itemData.imageURL,
[activeAnnotatedFile],
);
const performKeyAction = useCallback( const performKeyAction = useCallback(
(action): FileViewerPhotoSwipeDelegate["performKeyAction"] => { (action): FileViewerPhotoSwipeDelegate["performKeyAction"] => {
switch (action) { switch (action) {
case "delete": case "delete":
handleConfirmDelete?.(); if (activeAnnotatedFile?.annotation.showDelete)
handleConfirmDelete?.();
break; break;
case "copy": case "copy":
if (activeImageURL) handleCopyImage(); if (canCopyImage()) handleCopyImage();
break; break;
case "toggle-fullscreen": case "toggle-fullscreen":
handleToggleFullscreen(); handleToggleFullscreen();
@@ -658,10 +666,10 @@ const FileViewer: React.FC<FileViewerProps> = ({
}, },
[ [
handleConfirmDelete, handleConfirmDelete,
activeAnnotatedFile,
activeImageURL,
handleCopyImage, handleCopyImage,
handleToggleFullscreen, handleToggleFullscreen,
activeAnnotatedFile,
canCopyImage,
], ],
); );
@@ -794,18 +802,15 @@ const FileViewer: React.FC<FileViewerProps> = ({
<DeleteIcon /> <DeleteIcon />
</MoreMenuItem> </MoreMenuItem>
)} )}
{activeAnnotatedFile?.annotation.showCopyImage && {canCopyImage() && (
activeImageURL && ( <MoreMenuItem onClick={handleCopyImage}>
<MoreMenuItem onClick={handleCopyImage}> <MoreMenuItemTitle>
<MoreMenuItemTitle> {/*TODO */ pt("Copy as PNG")}
{/*TODO */ pt("Copy as PNG")} </MoreMenuItemTitle>
</MoreMenuItemTitle> {/* Tweak icon size to visually fit better with neighbours */}
{/* Tweak icon size to visually fit better with neighbours */} <ContentCopyIcon sx={{ "&&": { fontSize: "18px" } }} />
<ContentCopyIcon </MoreMenuItem>
sx={{ "&&": { fontSize: "18px" } }} )}
/>
</MoreMenuItem>
)}
{activeAnnotatedFile?.annotation.showEditImage && ( {activeAnnotatedFile?.annotation.showEditImage && (
<MoreMenuItem onClick={handleEditImage}> <MoreMenuItem onClick={handleEditImage}>
<MoreMenuItemTitle> <MoreMenuItemTitle>
@@ -930,7 +935,7 @@ const Shortcuts: React.FC<ModalVisibilityProps> = ({ open, onClose }) => (
<Shortcut action="Zoom" shortcut="Mouse scroll, Pinch" /> <Shortcut action="Zoom" shortcut="Mouse scroll, Pinch" />
<Shortcut action="Zoom preset" shortcut="Z, Tap inside image" /> <Shortcut action="Zoom preset" shortcut="Z, Tap inside image" />
<Shortcut action="Toggle controls" shortcut="Tap outside image" /> <Shortcut action="Toggle controls" shortcut="Tap outside image" />
<Shortcut action="Pan" shortcut="WASD, Drag" /> <Shortcut action="Pan" shortcut="W / A / S / D, Drag" />
<Shortcut action="Toggle favorite" shortcut="L" /> <Shortcut action="Toggle favorite" shortcut="L" />
<Shortcut action="View info" shortcut="I" /> <Shortcut action="View info" shortcut="I" />
<Shortcut action="Download" shortcut="K" /> <Shortcut action="Download" shortcut="K" />

View File

@@ -304,7 +304,7 @@ export class FileViewerPhotoSwipe {
const currentAnnotatedFile = () => { const currentAnnotatedFile = () => {
const file = currentFile(); const file = currentFile();
const annotatedFile = _currentAnnotatedFile; let annotatedFile = _currentAnnotatedFile;
if (!annotatedFile || annotatedFile.file.fileID != file.id) { if (!annotatedFile || annotatedFile.file.fileID != file.id) {
annotatedFile = onAnnotate(file, pswp.currSlide.content.data); annotatedFile = onAnnotate(file, pswp.currSlide.content.data);
_currentAnnotatedFile = annotatedFile; _currentAnnotatedFile = annotatedFile;
@@ -733,8 +733,9 @@ export class FileViewerPhotoSwipe {
const e: KeyboardEvent = pswpEvent.originalEvent; const e: KeyboardEvent = pswpEvent.originalEvent;
const key = e.key;
// Even though we ignore shift, Caps lock might still be on. // Even though we ignore shift, Caps lock might still be on.
const key = e.key.toLowerCase(); const lkey = e.key.toLowerCase();
// Keep the keybindings such that they don't use modifiers, because // Keep the keybindings such that they don't use modifiers, because
// these are more likely to interfere with browser shortcuts. // these are more likely to interfere with browser shortcuts.
@@ -747,17 +748,23 @@ export class FileViewerPhotoSwipe {
let cb: (() => void) | undefined; let cb: (() => void) | undefined;
if (e.shiftKey || e.altKey || e.metaKey || e.ctrlKey) { if (e.shiftKey || e.altKey || e.metaKey || e.ctrlKey) {
// Ignore except using Ctrl/Cmd-D for copy. // Ignore except using Ctrl/Cmd-C for copy.
if ((e.metaKey || e.ctrlKey) && key == "c") { if ((e.metaKey || e.ctrlKey) && lkey == "c") {
cb = handleCopy; cb = handleCopy;
} }
} else { } else {
switch (key) { switch (key) {
case "Backspace":
case "Delete":
cb = handleDelete;
break;
}
switch (lkey) {
case "w": case "w":
case "a": case "a":
case "s": case "s":
case "d": case "d":
cb = panner(key); cb = panner(lkey);
break; break;
case "l": case "l":
cb = handleToggleFavoriteIfEnabled; cb = handleToggleFavoriteIfEnabled;
@@ -768,10 +775,6 @@ export class FileViewerPhotoSwipe {
case "k": case "k":
cb = handleDownloadIfEnabled; cb = handleDownloadIfEnabled;
break; break;
case "Backspace":
case "Delete":
cb = handleDelete;
break;
case "f": case "f":
cb = handleToggleFullscreen; cb = handleToggleFullscreen;
break; break;