mirror of
https://github.com/usememos/memos.git
synced 2024-11-15 03:07:04 +08:00
feat: navigate image view with keyboard keys (#4116)
* Navigate images with keyboard left and right keys * Fix linting * Adding missing " * Added change to incorrect branch
This commit is contained in:
parent
bcd8856732
commit
142e97ab5a
1 changed files with 15 additions and 0 deletions
|
@ -94,6 +94,14 @@ const PreviewImageDialog: React.FC<Props> = ({ destroy, imgUrls, initialIndex }:
|
|||
}
|
||||
};
|
||||
|
||||
const handleImageContainerKeyDown = (event: KeyboardEvent) => {
|
||||
if (event.key == "ArrowLeft") {
|
||||
showPrevImg();
|
||||
} else if (event.key == "ArrowRight") {
|
||||
showNextImg();
|
||||
}
|
||||
};
|
||||
|
||||
const handleImgContainerScroll = (event: React.WheelEvent) => {
|
||||
const offsetX = event.nativeEvent.offsetX;
|
||||
const offsetY = event.nativeEvent.offsetY;
|
||||
|
@ -137,6 +145,13 @@ const PreviewImageDialog: React.FC<Props> = ({ destroy, imgUrls, initialIndex }:
|
|||
setViewportScalable();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
document.addEventListener("keydown", handleImageContainerKeyDown);
|
||||
return () => {
|
||||
document.removeEventListener("keydown", handleImageContainerKeyDown);
|
||||
};
|
||||
}, [currentIndex]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="btns-container">
|
||||
|
|
Loading…
Reference in a new issue