Paste an image from the clipboard - #69
Open
johnkattenhorn wants to merge 1 commit into
Open
johnkattenhorn wants to merge 1 commit into
johnkattenhorn wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #64.
Ctrl+Vpastes an image. It goes to animagesfolder beside the document, andthe document gets a relative reference to it:
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
PNG.
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 alocation.
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 thedocument, 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 thestatus says why.
./bin/test— 14 passing.Note
No new dependency, no UI, no new shortcut:
Ctrl+Valready had a paste path andthis is one more thing it recognises. Written against
masterat 8f98892.