Skip to content

Commit d78d0fc

Browse files
committed
feat: clicking preview on hover opens the file
1 parent 5346dd5 commit d78d0fc

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/Components/Layout/hover.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ const Hover = (): void => {
4949
}
5050
hoveringElement = target;
5151

52+
let openFromPreviewElementListener: { (): void; (this: HTMLDivElement, ev: MouseEvent): any; (this: HTMLDivElement, ev: MouseEvent): any } =
53+
null;
54+
5255
timeOut = window.setTimeout(async () => {
5356
displayName = filenameGrid.innerHTML;
5457
const path = decodeURI((await focusingPath()) === 'xplorer://Trash' ? target.dataset.realPath : target.dataset.path);
@@ -59,6 +62,11 @@ const Hover = (): void => {
5962
if (IMAGE_TYPES.indexOf(getExtension(filenameGrid.innerHTML)) !== -1 && previewImageOnHover) {
6063
hoverPreviewElement.innerHTML = `<img src="${new FileAPI(path).readAsset()}">`;
6164
hoverPreviewElement.classList.add('hover-preview');
65+
openFromPreviewElementListener = () => {
66+
new FileAPI(path).openFile();
67+
hoverPreviewElement.removeEventListener('click', openFromPreviewElementListener); //eslint-disable-line
68+
};
69+
hoverPreviewElement.addEventListener('click', openFromPreviewElementListener);
6270
document.body.appendChild(hoverPreviewElement);
6371

6472
if (hoverPreviewElement.clientWidth > window.innerWidth) hoverPreviewElement.style.width = `${0.5 * window.innerWidth}px`;

0 commit comments

Comments
 (0)