Skip to content

Paste an image from the clipboard - #69

Open
johnkattenhorn wants to merge 1 commit into
omacom:masterfrom
johnkattenhorn:upstream-image-paste
Open

johnkattenhorn wants to merge 1 commit into
omacom:masterfrom
johnkattenhorn:upstream-image-paste

Conversation

@johnkattenhorn

Copy link
Copy Markdown

Closes #64.

Ctrl+V pastes an image. It goes to an images folder beside the document, and
the document gets a relative reference to it:

![](images/pasted-20260917-142530.png)

Relative and under the document's own folder, so the document and its pictures
move, sync and open together — and so anything else that reads Markdown resolves
them the same way.

What it handles

  • Clipboard pixels — a screenshot, or Copy Image from a browser. Written as
    PNG.
  • A file on the clipboard — copied from a file manager. Copied rather than
    re-encoded, so whatever encoding and compression it already had survives.

Both run after the existing link paste, so a selection with a URL behind it
still becomes a link rather than a copy of the image.

What it refuses

An untitled document. It has no folder of its own, so an image put anywhere
would not survive being saved somewhere else. The status line says
Save the document first, then paste the image. rather than guessing a
location.

Naming

The clock names each image, so pastes stay in the order they were made and sort
that way in the folder. A counter goes behind it for two pastes inside the same
second.

Tests

Two, both in tst_omawrite.cpp:

  • writesAPastedImageBesideTheDocument — the reference resolves beside the
    document, the file is on disk at the right size, and a second paste in the
    same second takes a name of its own rather than writing over the first.
  • refusesToPasteAnImageIntoAnUntitledDocument — nothing written, and the
    status says why.

./bin/test — 14 passing.

Note

No new dependency, no UI, no new shortcut: Ctrl+V already had a paste path and
this is one more thing it recognises. Written against master at 8f98892.

Closes omacom#64.

Ctrl+V writes clipboard pixels, or an image file the clipboard carries as a URL,
into an `images` folder beside the document and inserts a relative reference to
it. Relative and under the document's own folder, so the document and its
pictures move together.

An untitled document is refused rather than guessed at: it has no folder of its
own, so an image put anywhere would not survive being saved somewhere else. The
status line says so instead.

A file on the clipboard is copied rather than re-encoded, which keeps whatever
encoding and compression it already had. Clipboard pixels are written as PNG.
The clock names each image so pastes stay in the order they were made, with a
counter behind it for two in the same second.

It runs after the existing link paste, so a selection with a URL behind it still
becomes a link rather than a copy of the image.
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: Allow pasting images in omawrite

1 participant