Skip to content

file viewer: a Copy action for the previewed file (#137) - #139

Merged
Lexus2016 merged 1 commit into
mainfrom
feat/fpv-copy-137
Nov 10, 2026
Merged

Lexus2016 merged 1 commit into
mainfrom
feat/fpv-copy-137

Conversation

@Lexus2016

Copy link
Copy Markdown
Owner

Fixes #137.

What this adds

A Copy action in the file preview toolbar, next to Download / Open / Share:

  • it appears only once the viewer has actually loaded text (text and markdown files), and is
    hidden for images, PDFs, binaries, refused reads and empty files — nothing to copy, nothing
    to press;
  • it copies the string that was fetched, not the pane, which is escaped HTML — so markdown
    copies as source;
  • it goes through the existing copyText() helper, which already falls back to a hidden
    textarea when navigator.clipboard is unavailable (plain http over a LAN or tunnel);
  • it works for a remote project as well: the text is already in memory, so nothing calls
    /api/files/raw or /api/files/download. Those are the endpoints issue Bug: File Browser Not Available for Remote SSH Projects #57 refuses, and
    the reason Download and Share stay hidden for remote projects.

Copying a selection needs no new code — Ctrl/Cmd+C in the pane already does that, and the
new button deliberately copies the whole file.

Tests

test/file-preview-copy.test.js (added to npm test) cuts the file-preview block out of
public/index.html and runs it in a vm with a stubbed fetch, $i, toast and clipboard —
no browser, no network. It checks the button's markup and default state, then: a text file
shows it and copies the fetched content, markdown copies its source, an empty file hides it
and copying is a no-op, binary/image/PDF previews and a refused read leave it hidden, closing
the viewer hides it and stops any copy, and reopening onto a failed read does not resurrect
the previous file's text.

Full local run on Node 24.22.1 (npm test, CI=1): 93 steps, the new file 21/21, and the i18n
parity suite 139/139 with the new keys in all five languages. Two steps went red in that run:
test/task-backlog.test.js and test/session-liveness.test.js. Both pass when run on their
own, and task-backlog fails the same way on unmodified main (measured on a clean worktree
of 2d95fe4) — pre-existing load-sensitive flakes, outside this change.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T18:21:52.053882Z 7ecf870 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

The preview toolbar offered Download, Open and Share but no way to take the file's
content, so copying meant opening the file elsewhere or dragging through the pane by
hand. The Copy button appears only once the viewer has actually loaded text, and copies
exactly the string that was fetched — the pane itself is escaped HTML.

It also works for a remote project: the text is already in memory, so it never reaches
/api/files/raw or /api/files/download, which is what issue #57 refuses and why Download
and Share stay hidden there.

Strings are added for all five languages the SPA ships.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7ecf870b8c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread public/index.html
Comment on lines +16088 to +16089
_fpvText = d.content || '';
$i('fpvCopyBtn').style.display = _fpvText ? '' : 'none';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Hide Copy when the API returns the oversized-file placeholder

For files larger than 2 MB, both the local /api/files handler and serveRemoteFiles() in server.js return [File too large to preview (>2 MB)] as content, rather than the file's text. This assignment treats that refusal as successfully loaded content, so Copy becomes visible, replaces the clipboard with the diagnostic string, and reports success. Exclude oversized-file responses from the copyable state so the action does not claim to copy file contents that were never fetched.

Useful? React with 👍 / 👎.

@Lexus2016
Lexus2016 merged commit 1a444b0 into main Nov 10, 2026
3 checks passed
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.

Feature Request: Add "Copy to Clipboard" Action in File Viewer

1 participant