Paste, drop or choose an image in any comment box and it uploads, as on GitHub.
Closes #159
How it works
- Where it's added: once, in
MentionTextarea(components/attach-images.tsx). An<AttachImages to=…>wrapper says where a page's images are kept. - Where it applies:
- pull request comments, reviews and inline line comments;
- editing a comment or the description;
- the "Mark ready" summary;
- commit comments;
- work item comments;
- the new pull request and new work item pages.
- While uploading:
![Uploading name…]()goes in at the caret, and only that placeholder is swapped for the image's Markdown when it's done. Typing around it is kept, and sending waits until every upload has finished. - On failure: the placeholder is removed and a sentence under the box says why. What you typed is never touched.
- Text pastes stay text: a paste uploads only when the clipboard holds image files and no plain text, so spreadsheet and Word pastes come in as text.
- Upload path: the new
POST /-/attachmentsresource route (same origin, signed in) calls the work service's existingupload_attachment, the pathg1t attach/--attachalready uses. That service checks who may upload, the type from the bytes, and the 10 MB limit. - A new work item with no repository: there's nowhere to keep images until the item exists, so they're sent with the form and attached to the item once it's made, as
g1t work new --attachdoes. In that case only, an upload that fails on the server is quietly left out, because the page has already moved on.
Tests
npx tsc -b --forceinapps/web: clean.npm testinapps/web: passing, including 11 new tests for the placeholder and clipboard logic (lib/attachments.ts).- I looked at the composer in light and dark, at desktop and phone widths, rendered with a mocked upload (screenshot below). Real clipboard and drag behaviour still wants a try in a browser on the deployed site.