Skip to content

feat(mobile): open documents linked from a preview, with a back stack - #825

Merged
huichen merged 1 commit into
mainfrom
feat/mobile-preview-links
Sep 25, 2026
Merged

huichen merged 1 commit into
mainfrom
feat/mobile-preview-links

Conversation

@huichen

@huichen huichen commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

What

A local-file link inside a previewed Markdown document was answered with "Markdown 预览中的本地文件链接请在桌面端查看。" (the alert in the screenshot). Now it opens, and the document that linked to it stays open underneath with a back control.

Why it was refused, and why that no longer holds

MarkdownText's mode="file-preview" branch blocked local links deliberately ("file previews never nest previews", #299). Everything needed to open the target already exists: the same link in a chat bubble goes through openFileLink, which handles the 10 MB limit, the type routing (image/markdown/text/JSON preview vs open/save/share), the progress Modal and the byte cache. What was missing was resolution and a place to come back to.

Changes

  • Resolution — a link inside a previewed document resolves against that document, via the resolver the document's images already use (markdownImagePath → resolveMarkdownPath). The old notice survives for the one unresolvable case: a document opened from this phone's own storage, where a relative path names nothing the desktop can read. That message is reworded to say so.
  • Stack — useFileDownload holds previews: PreviewState[]; preview is the top. openFileLink (chat) replaces the stack, openLinkedFile (a link inside a document) pushes. popPreview leaves one document; closePreview leaves the reader.
  • Layers — PreviewModal renders every open document as its own absolutely-filled layer, top one interactive, the ones below mounted and untouched so their scroll position survives. Keys are per document per visit, so A → B → A gives the new A its own layer instead of reusing B's rows.
  • Menu ownership — the overflow menu moved to the stack owner, because every event that must close it (a download starting, the stack changing, a native dismissal) lands there and none of them reaches into a layer.
  • Non-previewable targets — a link to a PDF/zip closes the stack first and opens the action sheet, the contract the preview's own menu actions already follow (the sheet is a second Modal, which iOS will not present over the preview).

Out of scope

The 10 MB and unknown-MIME limits are unchanged, #anchor links stay inert, and desktop keeps rendering local links as inert text.

Verification

npm run typecheck, npm run lint, and the full mobile Jest suite (125 suites / 1921 tests) in the worktree. New coverage: link resolution from inside a document (including the phone-local refusal), stack push/pop/replace, hardware back leaving one document at a time, layer key identity, and the menu rules.

Not verified on a device or in the screenshot harness — no visual/gesture check of the new back control.

A local-file link inside a previewed document was answered with "view it in
the desktop app", even though the phone can already open a local file from a
chat bubble. The refusal was deliberate once ("file previews never nest
previews"), but the machinery was already there: the same link in the chat
opens the target in place.

- `MarkdownText` resolves a link from a previewed document against that
  document, reusing the resolver its images already use, and hands the
  resolved path to the caller's preview flow. The notice stays for the one
  case that genuinely cannot be resolved: a document opened from this phone's
  own storage.
- Previews become a stack. The document that linked here stays mounted below
  the top one, so the back control (and Android's hardware back) returns to
  the same place in the same document. Layers are keyed by document per
  visit, so A → B → A does not reuse B's rows.
- The overflow menu moves to the stack owner: a download, a stack change, or
  a native dismissal all have to close it, and none of those reaches into a
  layer.
- A link whose target needs an external reader closes the stack first, the
  way the preview's own menu actions do: the action sheet is a second Modal
  and iOS will not present it over the preview.
@huichen
huichen enabled auto-merge (squash) September 25, 2026 09:36
@huichen
huichen merged commit c640e01 into main Sep 25, 2026
12 checks passed
@huichen
huichen deleted the feat/mobile-preview-links branch September 25, 2026 09:39
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.

1 participant