Skip to content

feat: quick file preview for images, PDF, docx, and more - #2

Closed
beihai23 wants to merge 24 commits into
mainfrom
worktree-feature-file-preview
Closed

feat: quick file preview for images, PDF, docx, and more#2
beihai23 wants to merge 24 commits into
mainfrom
worktree-feature-file-preview

Conversation

@beihai23

Copy link
Copy Markdown

Summary

marka.md only opens .md/.markdown/.mdx/.csv. Clicking any other file (image, PDF, docx, video, config.json, …) hits the binary-signature guard and shows a bare "open in default app" toast — there's no way to glance at a file inside the app. This adds an in-app quick preview overlay, with zero new dependencies.

What it does

A new fullscreen overlay (FilePreviewOverlay) mirrors the existing DiagramViewerOverlay chrome and renders each file type natively:

Type Rendering
Images (png/jpg/gif/webp/svg/bmp/avif/…) <img> with zoom / fit / drag-pan / ctrl-wheel
Video (mp4/mov/webm/…) <video controls>
Audio (mp3/wav/flac/…) <audio controls>
PDF <iframe> via webview-native rendering
Text / code (json/yaml/sh/…) read-only <pre> + "open as text" to edit
Office / unknown (docx/xlsx/pptx/zip/…) info card + "open in default app"

Binary files are read once via @tauri-apps/plugin-fs readFile → blob/data URL (PDF uses a data URL for webview-iframe compatibility; blob URLs are revoked on close). No new Tauri permissions are required — fs:allow-read-file and opener:allow-open-path are already granted.

Triggers

  • Click a previewable file → preview (replaces the old toast)
  • Context menu → "quick preview"
  • Space on a focused sidebar row (Finder Quick Look style)

.md/.csv keep opening in the editor as before. The toolbar shows a quick preview badge + esc to close hint so it's clearly read-only; on macOS the toolbar left-padding clears the native traffic-light buttons.

Behavior change

Clicking a non-markdown file now opens the preview overlay instead of the load-error toast. Text/code files preview read-only with an "open as text" button, so editability is preserved (one click into the editor).

Key files

  • src/lib/preview.ts — extension → kind/mime classification (pure, tested)
  • src/components/overlays/file-preview-overlay.tsx — the overlay + per-kind renderers
  • src/styles/overlays/file-preview.css — overlay styles
  • src/app.tsx — routing (handleSelectFile), context-menu item, Space shortcut, overlay wiring
  • src/components/files/folder-node.tsxdata-mdv-tree-path on file rows (Space target)
  • 9 locales — new menu.quickPreview + preview.* keys

Verification

  • bun test — 31 pass (includes new tests/preview.test.ts for kind/mime classification)
  • bun run build (tsc + vite) ✅
  • cargo check --release ✅ (no Rust changes)
  • 9 locales all carry the new keys (no bare keys)

Manual QA still recommended across formats.

Out of scope / future

  • True docx/xlsx/pptx rendering (would need mammoth/pdf.js — intentionally zero-dep for now; info card + "open in default" covers it)
  • Tauri asset protocol (convertFileSrc) for streaming large media — current path reads the whole file, fine for typical preview sizes
  • Drag-drop into the window still routes only markdown

🤖 Generated with Claude Code

beihai23 and others added 24 commits July 10, 2026 22:53
Reuse the existing DiagramViewerOverlay (already shared by Mermaid and
PlantUML) for inline preview images, via a new decorateImages step that
mirrors decorateMermaidBlocks / decoratePlantUmlBlocks.

- single-click any preview image to open the fullscreen viewer
- cursor: zoom-in + draggable=false suppress native image drag
- excludes images inside .mdv-plantuml and pre.mdv-mermaid (own affordance)
- svg images (*.svg, data:image/svg+xml) work via native <img> support;
  naturalWidth falls back to the rendered box when svg reports 0
- no change to the overlay component, Mermaid/PlantUML wiring, i18n, or Rust

Co-Authored-By: Claude <noreply@anthropic.com>
* feat(preview): unified reading width + outline (TOC) panel

Two reading-mode enhancements:

1. Unify preview width into the reading-width control
   - Remove the standalone "fill width" toggle; its behavior (fill
     viewport + 100% tables + tighter padding) moves into the "full"
     step of the existing reading-width slider.
   - Split preview now follows reading-width too — .mdv-prose uses the
     --mdv-reading-prose-width variable instead of a hardcoded 720px.
   - One width control (narrow / comfort / wide / full), effective in
     both split and reading modes, persisted.

2. Add a docked table-of-contents (outline) panel for reading mode
   - Toggle from the reading-mode title bar or the command palette.
   - Reads the rendered headings (each already carries a GitHub-style
     slug id from the markdown renderer) and scrolls to the chosen
     heading on click. State persisted.

Co-Authored-By: Claude <noreply@anthropic.com>

* fix(preview): refine outline behavior

* fix(editor): tighten gutter inset

* style(editor): define line number gutter

* polish editor gutter

---------

Co-authored-by: wangzhigang <wangzhigang@ont.io>
Co-authored-by: Claude <noreply@anthropic.com>
* Add zh-TW

* Add Traditional Chinese language support
Bumps [typescript](https://github.com/microsoft/TypeScript) from 5.9.3 to 7.0.2.
- [Release notes](https://github.com/microsoft/TypeScript/releases)
- [Commits](https://github.com/microsoft/TypeScript/commits)

---
updated-dependencies:
- dependency-name: typescript
  dependency-version: 7.0.2
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [serde_with](https://github.com/jonasbb/serde_with) from 3.20.0 to 3.21.0.
- [Release notes](https://github.com/jonasbb/serde_with/releases)
- [Commits](jonasbb/serde_with@v3.20.0...v3.21.0)

---
updated-dependencies:
- dependency-name: serde_with
  dependency-version: 3.21.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
…le10#112)

* feat(files): refresh open folders automatically

* refactor(files): use native tauri folder watching

* perf: lazy-load markdown rendering and native file watching
…rle10#113)

Bumps [tauri-plugin-single-instance](https://github.com/tauri-apps/plugins-workspace) from 2.4.2 to 2.4.3.
- [Release notes](https://github.com/tauri-apps/plugins-workspace/releases)
- [Commits](tauri-apps/plugins-workspace@fs-v2.4.2...fs-v2.4.3)

---
updated-dependencies:
- dependency-name: tauri-plugin-single-instance
  dependency-version: 2.4.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…attenarle10#114)

Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.150 to 1.0.151.
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](serde-rs/json@v1.0.150...v1.0.151)

---
updated-dependencies:
- dependency-name: serde_json
  dependency-version: 1.0.151
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…attenarle10#115)

Bumps [window-vibrancy](https://github.com/tauri-apps/tauri-plugin-vibrancy) from 0.7.1 to 0.8.0.
- [Release notes](https://github.com/tauri-apps/tauri-plugin-vibrancy/releases)
- [Changelog](https://github.com/tauri-apps/window-vibrancy/blob/dev/CHANGELOG.md)
- [Commits](tauri-apps/window-vibrancy@window-vibrancy-v0.7.1...window-vibrancy-v0.8.0)

---
updated-dependencies:
- dependency-name: window-vibrancy
  dependency-version: 0.8.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…ri (mattenarle10#116)

Bumps [tauri-plugin-dialog](https://github.com/tauri-apps/plugins-workspace) from 2.7.1 to 2.7.2.
- [Release notes](https://github.com/tauri-apps/plugins-workspace/releases)
- [Commits](tauri-apps/plugins-workspace@log-v2.7.1...dialog-v2.7.2)

---
updated-dependencies:
- dependency-name: tauri-plugin-dialog
  dependency-version: 2.7.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…arle10#117)

Bumps [serde](https://github.com/serde-rs/serde) from 1.0.228 to 1.0.229.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](serde-rs/serde@v1.0.228...v1.0.229)

---
updated-dependencies:
- dependency-name: serde
  dependency-version: 1.0.229
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Clicking a non-markdown file in the sidebar now opens an in-app preview
instead of the "open in default app" toast. Zero new dependencies.

- images/video/audio: native renderers via blob url
- pdf: webview-native iframe via data url
- text/code: read-only <pre> with "open as text" to edit
- office/unknown formats: info card + "open in default app"

Triggers: click, context menu "quick preview", and Space (Finder Quick
Look) on a focused sidebar row. .md/.csv keep opening in the editor.
macOS toolbar left-padding clears the native traffic-light buttons.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@beihai23
beihai23 force-pushed the worktree-feature-file-preview branch from 321bdb8 to 9989ac0 Compare July 24, 2026 09:58
@beihai23

Copy link
Copy Markdown
Author

Closing in favor of the upstream PR: mattenarle10#120 (this one was opened against the fork's own main by mistake). The branch is kept as the head of the upstream PR.

@beihai23 beihai23 closed this Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants