@@ -2,7 +2,7 @@ import React, { KeyboardEvent as KE, ReactNode, useCallback, useEffect, useMemo,
22import { useStores } from '$src/hooks/useStores'
33import { Button , Classes , Colors , Dialog , Icon } from '@blueprintjs/core'
44import { observer } from 'mobx-react'
5- import DocViewer , { DocViewerRenderers , IConfig } from 'react-doc-viewer'
5+ import DocViewer , { DocViewerRenderers , IConfig , IDocument } from 'react-doc-viewer'
66import { TypeIcons } from '$src/constants/icons'
77import { formatBytes } from '$src/utils/formatBytes'
88import { FileDescriptor } from '$src/services/Fs'
@@ -28,13 +28,16 @@ export const PreviewDialog = observer(() => {
2828 const view = appState . activeView
2929 const cache = view . getVisibleCache ( )
3030 const cursorIndex = cache . getFileIndex ( cache . cursor )
31+ const currentFile = cache . join ( cache . cursor . dir , cache . cursor . fullname ) . replace ( / # / g, '%23' )
3132 const docs = useMemo ( ( ) => {
3233 return cache . files . map ( ( file ) => ( { uri : cache . join ( file . dir , file . fullname ) . replace ( / # / g, '%23' ) } ) )
33- } , [ cache . cursor ] )
34- const activeDocument = docs [ cursorIndex ]
35- const { isDir, type, length, mDate } = cache . cursor || ( { } as FileDescriptor )
34+ } , [ currentFile ] )
35+ const activeDocumentRef = useRef < IDocument > ( {
36+ ...docs [ cursorIndex ] ,
37+ } )
38+ activeDocumentRef . current . uri = docs [ cursorIndex ] . uri
39+ const { isDir, type } = cache . cursor || ( { } as FileDescriptor )
3640 const icon = ( isDir && TypeIcons [ 'dir' ] ) || ( type && TypeIcons [ type ] ) || TypeIcons [ 'any' ]
37- const size = ( length && formatBytes ( length ) ) || 0
3841 const theme = settingsState . isDarkModeActive ? darkTheme : lightTheme
3942
4043 const Header = ( { cache } : { cache : FileState } ) => {
@@ -70,6 +73,9 @@ export const PreviewDialog = observer(() => {
7073 const NoPreviewRenderer = ( { document, fileName } : any ) => {
7174 const { t } = useTranslation ( )
7275 const fileText = fileName || document ?. fileType || ''
76+ const { mDate, length, type, isDir } = cache . cursor
77+ const icon = ( isDir && TypeIcons [ 'dir' ] ) || ( type && TypeIcons [ type ] ) || TypeIcons [ 'any' ]
78+ const size = ( length && formatBytes ( length ) ) || 0
7379 const modifiedString = ( mDate && t ( 'DIALOG.PREVIEW.LAST_MODIFIED_ON' , { date : mDate . toLocaleString ( ) } ) ) || ''
7480
7581 return (
@@ -123,8 +129,8 @@ export const PreviewDialog = observer(() => {
123129 } }
124130 config = { viewerConfig }
125131 documents = { docs }
126- initialActiveDocument = { activeDocument }
127- activeDocument = { activeDocument }
132+ initialActiveDocument = { activeDocumentRef . current }
133+ activeDocument = { activeDocumentRef . current }
128134 pluginRenderers = { DocViewerRenderers }
129135 theme = { theme }
130136 />
0 commit comments