1# Attaching files from the editor
2
3`candidate/` is `crates/canvas/tests/attachment_insert.rs`'s section: the editor
4attaches `notes 🦀.txt` (30 bytes, with the icon OneNote stored for a text file)
5at the end of "Before the file", "After the file" is typed where the caret
6lands, and `large.bin` (2 MiB of noise, with the canvas's blank-page icon, as
7a host without system icons stores it) is attached after that. Each step is its
8own edit of the ops the editor recorded, sealed into one appended revision.
9`cold/` is a fresh OneNote 2010 read: both files in place, and the bytes OneNote
10materializes to open them (`read/*.attachment`) hash as written. Opened by
11double click and saved by Save As in a lab clone, both matched too.
12`tools/test_attachment_insert.py` checks the capture without a VM. Regenerate
13with `CANVAS_ATTACHMENT_EXPORT` set to a directory while running the test, then
14`tools/native_runner.py DIR COLD --expected-pages 1 --collect-notebook
15--screenshots`.
16
17`without-icon.png` is OneNote opening a file stored without the icon: it draws
18a broken picture, so the editor always stores one.
19
20## What OneNote 2010 does
21
22Observed in a lab clone on 2026-09-29:
23
24- **Storage.** Every attachment goes into the section's own file data store,
25 whatever its size (1 KiB to 300 MiB, through COM and through Insert > Attach
26 File, on a local folder and on a share). OneNote never wrote a `_onefiles`
27 folder. Identical bytes are stored once per section: a second attachment of
28 the same file, or the same icon, references the first payload. Snowbound
29 stores each attachment's bytes anew, which OneNote reads the same.
30- **Icon.** Beside each file it stores a 32-pixel PNG of the file type's
31 system icon, drawn at 24 points, over the name without its extension.
32- **Attach File and drops.** At the caret, the paragraph splits there: the file
33 follows the text before the caret (or replaces an empty first half) and the
34 text after it follows the file with the caret, as an empty paragraph at the
35 end of one. A drop on text does the same at the drop point, after asking
36 whether to attach a copy (the default) or link to the original. Attached or
37 dropped on blank page, the file becomes a page-level object at that point.
38- **Open.** A double click or Open warns once ("Opening attachments could harm
39 your computer and data") and opens a copy from
40 `%TEMP%\OneNote\14.0\NT\N\` under the file's own name. The context menu
41 offers Open, Save As (in the source's folder, under its name), Insert as
42 Printout, Open Original and Copy Link to Original.