feat: enable inline preview for image files (PNG, SVG, JPEG, etc.)

Images that can be rendered in the browser (png, jpg, jpeg, gif, bmp, webp,
svg, ico) now open in the file preview panel instead of launching an external
application. Raw image formats (tiff, heic, heif) still open externally since
they require specialized decoders.

The change updates shouldOpenExternally() to use the existing isImageFile()
helper from gitUtils, ensuring consistency with other image handling throughout
the codebase. Added comprehensive tests for image file handling.

Claude ID: ad65a8b7-fc6f-4ebc-86be-ec86f66a0120
Maestro ID: b9bc0d08-5be2-4fdf-93cd-5618a8d53b35
This commit is contained in:
Pedram Amini
2025-12-27 01:48:59 -06:00
parent 59fce66462
commit ab982156f6
2 changed files with 40 additions and 2 deletions

View File

@@ -94,6 +94,38 @@ describe('fileExplorer utils', () => {
});
});
describe('image files (previewable inline)', () => {
it('returns false for PNG files (previewable)', () => {
expect(shouldOpenExternally('image.png')).toBe(false);
expect(shouldOpenExternally('screenshot.PNG')).toBe(false);
});
it('returns false for SVG files (previewable)', () => {
expect(shouldOpenExternally('icon.svg')).toBe(false);
expect(shouldOpenExternally('logo.SVG')).toBe(false);
});
it('returns false for JPEG files (previewable)', () => {
expect(shouldOpenExternally('photo.jpg')).toBe(false);
expect(shouldOpenExternally('photo.jpeg')).toBe(false);
expect(shouldOpenExternally('photo.JPEG')).toBe(false);
});
it('returns false for other previewable image formats', () => {
expect(shouldOpenExternally('image.gif')).toBe(false);
expect(shouldOpenExternally('image.webp')).toBe(false);
expect(shouldOpenExternally('image.bmp')).toBe(false);
expect(shouldOpenExternally('favicon.ico')).toBe(false);
});
it('returns true for non-previewable image formats', () => {
expect(shouldOpenExternally('photo.tiff')).toBe(true);
expect(shouldOpenExternally('photo.tif')).toBe(true);
expect(shouldOpenExternally('photo.heic')).toBe(true);
expect(shouldOpenExternally('photo.heif')).toBe(true);
});
});
describe('code and text files', () => {
it('returns false for TypeScript files', () => {
expect(shouldOpenExternally('app.ts')).toBe(false);

View File

@@ -2,18 +2,24 @@ import {
getAllFolderPaths as getAllFolderPathsShared,
walkTreePartitioned,
} from '../../shared/treeUtils';
import { isImageFile } from '../../shared/gitUtils';
/**
* Check if a file should be opened in external app based on extension
*/
export function shouldOpenExternally(filename: string): boolean {
// Images that can be previewed inline should NOT open externally
if (isImageFile(filename)) {
return false;
}
const ext = filename.split('.').pop()?.toLowerCase();
// File types that should open in default system app
const externalExtensions = [
// Documents
'pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx',
// Images (handled separately for preview, but open externally if double-clicked from file tree)
'png', 'jpg', 'jpeg', 'gif', 'bmp', 'svg', 'webp', 'tiff', 'tif', 'heic', 'heif',
// Images that can't be previewed inline (raw formats, etc.)
'tiff', 'tif', 'heic', 'heif',
// macOS/iOS specific
'icns', 'car', 'actool',
// Design files