Skip to content

Commit c35e855

Browse files
author
IM.codes
committed
fix(web): avoid local preview state in pinned browsers
1 parent 4c3429d commit c35e855

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

web/src/components/FileBrowser.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,10 @@ export function FileBrowser({
667667
if (editDirtyRef.current) {
668668
if (!window.confirm(t('fileBrowser.unsavedChanges'))) return;
669669
}
670+
if (onPreviewFile) {
671+
onPreviewFile({ path: filePath, preferDiff, preview: { status: 'loading', path: filePath } });
672+
return;
673+
}
670674
dismissedAutoPreviewPathRef.current = null;
671675
setEditDirty(false);
672676
setEditContent('');
@@ -675,10 +679,6 @@ export function FileBrowser({
675679
const loadingPreview: FileBrowserPreviewState = { status: 'loading', path: filePath };
676680
setPreview(loadingPreview);
677681
setShowDiff(preferDiff);
678-
if (onPreviewFile) {
679-
onPreviewFile({ path: filePath, preferDiff, preview: loadingPreview });
680-
return;
681-
}
682682
const requestId = ws.fsReadFile(filePath);
683683
pendingReadRef.current.set(requestId, filePath);
684684
const diffId = ws.fsGitDiff(filePath);
@@ -948,8 +948,8 @@ export function FileBrowser({
948948

949949
const alreadySet = new Set(alreadyInserted);
950950
const usesExternalPreview = !!onPreviewFile;
951-
const hasPreview = mode !== 'dir-only' && preview.status !== 'idle';
952-
const hasInlinePreview = hasPreview && !usesExternalPreview;
951+
const hasInlinePreview = mode !== 'dir-only' && preview.status !== 'idle' && !usesExternalPreview;
952+
const hasPreview = hasInlinePreview;
953953

954954
const previewPath = preview.status !== 'idle' ? (preview as { path: string }).path : null;
955955

web/test/components/FileBrowser.test.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,38 @@ describe('FileBrowser', () => {
824824
expect(onPreviewFile).toHaveBeenCalled();
825825
expect(document.querySelector('.fb-preview')).toBeNull();
826826
expect(document.querySelector('.fb-body-split')).toBeNull();
827+
expect(document.querySelector('.fb-tree-split')).toBeNull();
828+
expect(document.querySelector('.fb-resize-handle')).toBeNull();
829+
});
830+
831+
it('does not change the source panel layout when opening external previews from the files list', async () => {
832+
const { ws, respond } = makeWsFactory();
833+
const onPreviewFile = vi.fn();
834+
render(
835+
<FileBrowser
836+
ws={ws}
837+
mode="file-single"
838+
layout="panel"
839+
initialPath="/home/user"
840+
onPreviewFile={onPreviewFile}
841+
onConfirm={vi.fn()}
842+
/>,
843+
);
844+
845+
await act(async () => { respond([{ name: 'foo.ts', isDir: false }], '/home/user'); });
846+
847+
const fileEntry = await screen.findByText('foo.ts');
848+
await act(async () => { fireEvent.click(fileEntry); });
849+
850+
expect(onPreviewFile).toHaveBeenCalledWith({
851+
path: '/home/user/foo.ts',
852+
preferDiff: false,
853+
preview: { status: 'loading', path: '/home/user/foo.ts' },
854+
});
855+
expect(document.querySelector('.fb-preview')).toBeNull();
856+
expect(document.querySelector('.fb-body-split')).toBeNull();
857+
expect(document.querySelector('.fb-tree-split')).toBeNull();
858+
expect(document.querySelector('.fb-resize-handle')).toBeNull();
827859
});
828860

829861
it('hides the embedded changes section in files view when an external preview host is provided', async () => {

0 commit comments

Comments
 (0)